Debian Codegraph @

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