forked from fastly/go-fastly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcl_test.go
291 lines (260 loc) · 5.28 KB
/
vcl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package fastly
import "testing"
func TestClient_VCLs(t *testing.T) {
t.Parallel()
var err error
var tv *Version
record(t, "vcls/version", func(c *Client) {
tv = testVersion(t, c)
})
content := `
backend default {
.host = "127.0.0.1";
.port = "9092";
}
sub vcl_recv {
set req.backend = default;
}
sub vcl_hash {
set req.hash += req.url;
set req.hash += req.http.host;
set req.hash += "0";
}
`
// Create
var vcl *VCL
record(t, "vcls/create", func(c *Client) {
vcl, err = c.CreateVCL(&CreateVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "test-vcl",
Content: content,
})
})
if err != nil {
t.Fatal(err)
}
// Ensure deleted
defer func() {
record(t, "vcls/cleanup", func(c *Client) {
c.DeleteVCL(&DeleteVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "test-vcl",
})
c.DeleteVCL(&DeleteVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "new-test-vcl",
})
})
}()
if vcl.Name != "test-vcl" {
t.Errorf("bad name: %q", vcl.Name)
}
if vcl.Content != content {
t.Errorf("bad content: %q", vcl.Content)
}
// List
var vcls []*VCL
record(t, "vcls/list", func(c *Client) {
vcls, err = c.ListVCLs(&ListVCLsInput{
Service: testServiceID,
Version: tv.Number,
})
})
if err != nil {
t.Fatal(err)
}
if len(vcls) < 1 {
t.Errorf("bad vcls: %v", vcls)
}
// Get
var nvcl *VCL
record(t, "vcls/get", func(c *Client) {
nvcl, err = c.GetVCL(&GetVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "test-vcl",
})
})
if err != nil {
t.Fatal(err)
}
if vcl.Name != nvcl.Name {
t.Errorf("bad name: %q", vcl.Name)
}
if vcl.Content != nvcl.Content {
t.Errorf("bad address: %q", vcl.Content)
}
// Update
var uvcl *VCL
record(t, "vcls/update", func(c *Client) {
uvcl, err = c.UpdateVCL(&UpdateVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "test-vcl",
NewName: "new-test-vcl",
})
})
if err != nil {
t.Fatal(err)
}
if uvcl.Name != "new-test-vcl" {
t.Errorf("bad name: %q", uvcl.Name)
}
// Activate
var avcl *VCL
record(t, "vcls/activate", func(c *Client) {
avcl, err = c.ActivateVCL(&ActivateVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "new-test-vcl",
})
})
if err != nil {
t.Fatal(err)
}
if avcl.Main != true {
t.Errorf("bad main: %t", avcl.Main)
}
// Delete
record(t, "vcls/delete", func(c *Client) {
err = c.DeleteVCL(&DeleteVCLInput{
Service: testServiceID,
Version: tv.Number,
Name: "new-test-vcl",
})
})
if err != nil {
t.Fatal(err)
}
}
func TestClient_ListVCLs_validation(t *testing.T) {
var err error
_, err = testClient.ListVCLs(&ListVCLsInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.ListVCLs(&ListVCLsInput{
Service: "foo",
Version: 0,
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
}
func TestClient_CreateVCL_validation(t *testing.T) {
var err error
_, err = testClient.CreateVCL(&CreateVCLInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.CreateVCL(&CreateVCLInput{
Service: "foo",
Version: 0,
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
}
func TestClient_GetVCL_validation(t *testing.T) {
var err error
_, err = testClient.GetVCL(&GetVCLInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetVCL(&GetVCLInput{
Service: "foo",
Version: 0,
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetVCL(&GetVCLInput{
Service: "foo",
Version: 1,
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}
func TestClient_UpdateVCL_validation(t *testing.T) {
var err error
_, err = testClient.UpdateVCL(&UpdateVCLInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.UpdateVCL(&UpdateVCLInput{
Service: "foo",
Version: 0,
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
_, err = testClient.UpdateVCL(&UpdateVCLInput{
Service: "foo",
Version: 1,
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}
func TestClient_ActivateVCL_validation(t *testing.T) {
var err error
_, err = testClient.ActivateVCL(&ActivateVCLInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.ActivateVCL(&ActivateVCLInput{
Service: "foo",
Version: 0,
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
_, err = testClient.ActivateVCL(&ActivateVCLInput{
Service: "foo",
Version: 1,
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}
func TestClient_DeleteVCL_validation(t *testing.T) {
var err error
err = testClient.DeleteVCL(&DeleteVCLInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteVCL(&DeleteVCLInput{
Service: "foo",
Version: 0,
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteVCL(&DeleteVCLInput{
Service: "foo",
Version: 1,
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}