Debian Codegraph @

fastly/ftp_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package fastly
2
3 import "testing"
4
5 func TestClient_FTPs(t *testing.T) {
6 t.Parallel()
7
8 var err error
9 var tv *Version
10 record(t, "ftps/version", func(c *Client) {
11 tv = testVersion(t, c)
12 })
13
14 // Create
15 var ftp *FTP
16 record(t, "ftps/create", func(c *Client) {
17 ftp, err = c.CreateFTP(&CreateFTPInput{
18 Service: testServiceID,
19 Version: tv.Number,
20 Name: "test-ftp",
21 Address: "example.com",
22 Port: 1234,
23 Username: "username",
24 Password: "password",
25 Path: "/dir",
26 Period: 12,
27 GzipLevel: 9,
28 FormatVersion: 2,
29 Format: "format",
30 TimestampFormat: "%Y",
31 Placement: "waf_debug",
32 })
33 })
34 if err != nil {
35 t.Fatal(err)
36 }
37
38 // Ensure deleted
39 defer func() {
40 record(t, "ftps/cleanup", func(c *Client) {
41 c.DeleteFTP(&DeleteFTPInput{
42 Service: testServiceID,
43 Version: tv.Number,
44 Name: "test-ftp",
45 })
46
47 c.DeleteFTP(&DeleteFTPInput{
48 Service: testServiceID,
49 Version: tv.Number,
50 Name: "new-test-ftp",
51 })
52 })
53 }()
54
55 if ftp.Name != "test-ftp" {
56 t.Errorf("bad name: %q", ftp.Name)
57 }
58 if ftp.Address != "example.com" {
59 t.Errorf("bad address: %q", ftp.Address)
60 }
61 if ftp.Port != 1234 {
62 t.Errorf("bad port: %q", ftp.Port)
63 }
64 if ftp.Username != "username" {
65 t.Errorf("bad username: %q", ftp.Username)
66 }
67 if ftp.Password != "password" {
68 t.Errorf("bad password: %q", ftp.Password)
69 }
70 if ftp.Path != "/dir" {
71 t.Errorf("bad path: %q", ftp.Path)
72 }
73 if ftp.Period != 12 {
74 t.Errorf("bad period: %q", ftp.Period)
75 }
76 if ftp.GzipLevel != 9 {
77 t.Errorf("bad gzip_level: %q", ftp.GzipLevel)
78 }
79 if ftp.FormatVersion != 2 {
80 t.Errorf("bad format_version: %q", ftp.FormatVersion)
81 }
82 if ftp.Format != "format" {
83 t.Errorf("bad format: %q", ftp.Format)
84 }
85 if ftp.TimestampFormat != "%Y" {
86 t.Errorf("bad timestamp_format: %q", ftp.TimestampFormat)
87 }
88 if ftp.Placement != "waf_debug" {
89 t.Errorf("bad placement: %q", ftp.Placement)
90 }
91
92 // List
93 var ftps []*FTP
94 record(t, "ftps/list", func(c *Client) {
95 ftps, err = c.ListFTPs(&ListFTPsInput{
96 Service: testServiceID,
97 Version: tv.Number,
98 })
99 })
100 if err != nil {
101 t.Fatal(err)
102 }
103 if len(ftps) < 1 {
104 t.Errorf("bad ftps: %v", ftps)
105 }
106
107 // Get
108 var nftp *FTP
109 record(t, "ftps/get", func(c *Client) {
110 nftp, err = c.GetFTP(&GetFTPInput{
111 Service: testServiceID,
112 Version: tv.Number,
113 Name: "test-ftp",
114 })
115 })
116 if err != nil {
117 t.Fatal(err)
118 }
119 if ftp.Name != nftp.Name {
120 t.Errorf("bad name: %q", ftp.Name)
121 }
122 if ftp.Address != nftp.Address {
123 t.Errorf("bad address: %q", ftp.Address)
124 }
125 if ftp.Port != nftp.Port {
126 t.Errorf("bad port: %q", ftp.Port)
127 }
128 if ftp.Username != nftp.Username {
129 t.Errorf("bad username: %q", ftp.Username)
130 }
131 if ftp.Password != nftp.Password {
132 t.Errorf("bad password: %q", ftp.Password)
133 }
134 if ftp.Path != nftp.Path {
135 t.Errorf("bad path: %q", ftp.Path)
136 }
137 if ftp.Period != nftp.Period {
138 t.Errorf("bad period: %q", ftp.Period)
139 }
140 if ftp.GzipLevel != nftp.GzipLevel {
141 t.Errorf("bad gzip_level: %q", ftp.GzipLevel)
142 }
143 if ftp.FormatVersion != nftp.FormatVersion {
144 t.Errorf("bad format_version: %q", ftp.FormatVersion)
145 }
146 if ftp.Format != nftp.Format {
147 t.Errorf("bad format: %q", ftp.Format)
148 }
149 if ftp.TimestampFormat != nftp.TimestampFormat {
150 t.Errorf("bad timestamp_format: %q", ftp.TimestampFormat)
151 }
152 if ftp.Placement != nftp.Placement {
153 t.Errorf("bad placement: %q", ftp.Placement)
154 }
155
156 // Update
157 var uftp *FTP
158 record(t, "ftps/update", func(c *Client) {
159 uftp, err = c.UpdateFTP(&UpdateFTPInput{
160 Service: testServiceID,
161 Version: tv.Number,
162 Name: "test-ftp",
163 NewName: "new-test-ftp",
164 })
165 })
166 if err != nil {
167 t.Fatal(err)
168 }
169 if uftp.Name != "new-test-ftp" {
170 t.Errorf("bad name: %q", uftp.Name)
171 }
172
173 // Delete
174 record(t, "ftps/delete", func(c *Client) {
175 err = c.DeleteFTP(&DeleteFTPInput{
176 Service: testServiceID,
177 Version: tv.Number,
178 Name: "new-test-ftp",
179 })
180 })
181 if err != nil {
182 t.Fatal(err)
183 }
184 }
185
186 func TestClient_ListFTPs_validation(t *testing.T) {
187 var err error
188 _, err = testClient.ListFTPs(&ListFTPsInput{
189 Service: "",
190 })
191 if err != ErrMissingService {
192 t.Errorf("bad error: %s", err)
193 }
194
195 _, err = testClient.ListFTPs(&ListFTPsInput{
196 Service: "foo",
197 Version: 0,
198 })
199 if err != ErrMissingVersion {
200 t.Errorf("bad error: %s", err)
201 }
202 }
203
204 func TestClient_CreateFTP_validation(t *testing.T) {
205 var err error
206 _, err = testClient.CreateFTP(&CreateFTPInput{
207 Service: "",
208 })
209 if err != ErrMissingService {
210 t.Errorf("bad error: %s", err)
211 }
212
213 _, err = testClient.CreateFTP(&CreateFTPInput{
214 Service: "foo",
215 Version: 0,
216 })
217 if err != ErrMissingVersion {
218 t.Errorf("bad error: %s", err)
219 }
220 }
221
222 func TestClient_GetFTP_validation(t *testing.T) {
223 var err error
224 _, err = testClient.GetFTP(&GetFTPInput{
225 Service: "",
226 })
227 if err != ErrMissingService {
228 t.Errorf("bad error: %s", err)
229 }
230
231 _, err = testClient.GetFTP(&GetFTPInput{
232 Service: "foo",
233 Version: 0,
234 })
235 if err != ErrMissingVersion {
236 t.Errorf("bad error: %s", err)
237 }
238
239 _, err = testClient.GetFTP(&GetFTPInput{
240 Service: "foo",
241 Version: 1,
242 Name: "",
243 })
244 if err != ErrMissingName {
245 t.Errorf("bad error: %s", err)
246 }
247 }
248
249 func TestClient_UpdateFTP_validation(t *testing.T) {
250 var err error
251 _, err = testClient.UpdateFTP(&UpdateFTPInput{
252 Service: "",
253 })
254 if err != ErrMissingService {
255 t.Errorf("bad error: %s", err)
256 }
257
258 _, err = testClient.UpdateFTP(&UpdateFTPInput{
259 Service: "foo",
260 Version: 0,
261 })
262 if err != ErrMissingVersion {
263 t.Errorf("bad error: %s", err)
264 }
265
266 _, err = testClient.UpdateFTP(&UpdateFTPInput{
267 Service: "foo",
268 Version: 1,
269 Name: "",
270 })
271 if err != ErrMissingName {
272 t.Errorf("bad error: %s", err)
273 }
274 }
275
276 func TestClient_DeleteFTP_validation(t *testing.T) {
277 var err error
278 err = testClient.DeleteFTP(&DeleteFTPInput{
279 Service: "",
280 })
281 if err != ErrMissingService {
282 t.Errorf("bad error: %s", err)
283 }
284
285 err = testClient.DeleteFTP(&DeleteFTPInput{
286 Service: "foo",
287 Version: 0,
288 })
289 if err != ErrMissingVersion {
290 t.Errorf("bad error: %s", err)
291 }
292
293 err = testClient.DeleteFTP(&DeleteFTPInput{
294 Service: "foo",
295 Version: 1,
296 Name: "",
297 })
298 if err != ErrMissingName {
299 t.Errorf("bad error: %s", err)
300 }
301 }