forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
426 lines (394 loc) · 13.7 KB
/
fixtures.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
// SingleL7PolicyBody is the canned body of a Get request on an existing l7policy.
const SingleL7PolicyBody = `
{
"l7policy": {
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"description": "",
"admin_state_up": true,
"redirect_pool_id": null,
"redirect_url": "http://www.example.com",
"action": "REDIRECT_TO_URL",
"position": 1,
"project_id": "e3cd678b11784734bc366148aa37580e",
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
"name": "redirect-example.com",
"rules": []
}
}
`
var (
L7PolicyToURL = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "redirect-example.com",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_URL",
Position: 1,
Description: "",
ProjectID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectURL: "http://www.example.com",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
L7PolicyToPool = l7policies.L7Policy{
ID: "964f4ba4-f6cd-405c-bebd-639460af7231",
Name: "redirect-pool",
ListenerID: "be3138a3-5cf7-4513-a4c2-bb137e668bab",
Action: "REDIRECT_TO_POOL",
Position: 1,
Description: "",
ProjectID: "c1f7910086964990847dc6c8b128f63c",
RedirectPoolID: "bac433c6-5bea-4311-80da-bd1cd90fbd25",
RedirectURL: "",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
L7PolicyUpdated = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "NewL7PolicyName",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_URL",
Position: 1,
Description: "Redirect requests to example.com",
ProjectID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectURL: "http://www.new-example.com",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
L7PolicyNullRedirectURLUpdated = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "NewL7PolicyName",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_URL",
Position: 1,
Description: "Redirect requests to example.com",
ProjectID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectURL: "",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
RulePath = l7policies.Rule{
ID: "16621dbb-a736-4888-a57a-3ecd53df784c",
RuleType: "PATH",
CompareType: "REGEX",
Value: "/images*",
ProjectID: "e3cd678b11784734bc366148aa37580e",
Key: "",
Invert: true,
AdminStateUp: true,
}
RuleHostName = l7policies.Rule{
ID: "d24521a0-df84-4468-861a-a531af116d1e",
RuleType: "HOST_NAME",
CompareType: "EQUAL_TO",
Value: "www.example.com",
ProjectID: "e3cd678b11784734bc366148aa37580e",
Key: "",
Invert: false,
AdminStateUp: true,
}
RuleUpdated = l7policies.Rule{
ID: "16621dbb-a736-4888-a57a-3ecd53df784c",
RuleType: "PATH",
CompareType: "REGEX",
Value: "/images/special*",
ProjectID: "e3cd678b11784734bc366148aa37580e",
Key: "",
Invert: false,
AdminStateUp: true,
}
)
// HandleL7PolicyCreationSuccessfully sets up the test server to respond to a l7policy creation request
// with a given response.
func HandleL7PolicyCreationSuccessfully(t *testing.T, response string) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{
"l7policy": {
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"redirect_url": "http://www.example.com",
"name": "redirect-example.com",
"action": "REDIRECT_TO_URL"
}
}`)
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
})
}
// L7PoliciesListBody contains the canned body of a l7policy list response.
const L7PoliciesListBody = `
{
"l7policies": [
{
"redirect_pool_id": null,
"description": "",
"admin_state_up": true,
"rules": [],
"project_id": "e3cd678b11784734bc366148aa37580e",
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"redirect_url": "http://www.example.com",
"action": "REDIRECT_TO_URL",
"position": 1,
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
"name": "redirect-example.com"
},
{
"redirect_pool_id": "bac433c6-5bea-4311-80da-bd1cd90fbd25",
"description": "",
"admin_state_up": true,
"rules": [],
"project_id": "c1f7910086964990847dc6c8b128f63c",
"listener_id": "be3138a3-5cf7-4513-a4c2-bb137e668bab",
"action": "REDIRECT_TO_POOL",
"position": 1,
"id": "964f4ba4-f6cd-405c-bebd-639460af7231",
"name": "redirect-pool"
}
]
}
`
// PostUpdateL7PolicyBody is the canned response body of a Update request on an existing l7policy.
const PostUpdateL7PolicyBody = `
{
"l7policy": {
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"description": "Redirect requests to example.com",
"admin_state_up": true,
"redirect_url": "http://www.new-example.com",
"action": "REDIRECT_TO_URL",
"position": 1,
"project_id": "e3cd678b11784734bc366148aa37580e",
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
"name": "NewL7PolicyName",
"rules": []
}
}
`
// PostUpdateL7PolicyNullRedirectURLBody is the canned response body of a Update request
// on an existing l7policy with a null redirect_url .
const PostUpdateL7PolicyNullRedirectURLBody = `
{
"l7policy": {
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"description": "Redirect requests to example.com",
"admin_state_up": true,
"redirect_url": null,
"action": "REDIRECT_TO_URL",
"position": 1,
"project_id": "e3cd678b11784734bc366148aa37580e",
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
"name": "NewL7PolicyName",
"rules": []
}
}
`
// HandleL7PolicyListSuccessfully sets up the test server to respond to a l7policy List request.
func HandleL7PolicyListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, L7PoliciesListBody)
case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab":
fmt.Fprintf(w, `{ "l7policies": [] }`)
default:
t.Fatalf("/v2.0/lbaas/l7policies invoked with unexpected marker=[%s]", marker)
}
})
}
// HandleL7PolicyGetSuccessfully sets up the test server to respond to a l7policy Get request.
func HandleL7PolicyGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
fmt.Fprintf(w, SingleL7PolicyBody)
})
}
// HandleL7PolicyDeletionSuccessfully sets up the test server to respond to a l7policy deletion request.
func HandleL7PolicyDeletionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
}
// HandleL7PolicyUpdateSuccessfully sets up the test server to respond to a l7policy Update request.
func HandleL7PolicyUpdateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestJSONRequest(t, r, `{
"l7policy": {
"name": "NewL7PolicyName",
"action": "REDIRECT_TO_URL",
"redirect_url": "http://www.new-example.com"
}
}`)
fmt.Fprintf(w, PostUpdateL7PolicyBody)
})
}
// HandleL7PolicyUpdateNullRedirectURLSuccessfully sets up the test server to respond to a l7policy Update request.
func HandleL7PolicyUpdateNullRedirectURLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestJSONRequest(t, r, `{
"l7policy": {
"name": "NewL7PolicyName",
"redirect_url": null
}
}`)
fmt.Fprintf(w, PostUpdateL7PolicyNullRedirectURLBody)
})
}
// SingleRuleBody is the canned body of a Get request on an existing rule.
const SingleRuleBody = `
{
"rule": {
"compare_type": "REGEX",
"invert": true,
"admin_state_up": true,
"value": "/images*",
"key": null,
"project_id": "e3cd678b11784734bc366148aa37580e",
"type": "PATH",
"id": "16621dbb-a736-4888-a57a-3ecd53df784c"
}
}
`
// HandleRuleCreationSuccessfully sets up the test server to respond to a rule creation request
// with a given response.
func HandleRuleCreationSuccessfully(t *testing.T, response string) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{
"rule": {
"compare_type": "REGEX",
"type": "PATH",
"value": "/images*"
}
}`)
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
})
}
// RulesListBody contains the canned body of a rule list response.
const RulesListBody = `
{
"rules":[
{
"compare_type": "REGEX",
"invert": true,
"admin_state_up": true,
"value": "/images*",
"key": null,
"project_id": "e3cd678b11784734bc366148aa37580e",
"type": "PATH",
"id": "16621dbb-a736-4888-a57a-3ecd53df784c"
},
{
"compare_type": "EQUAL_TO",
"invert": false,
"admin_state_up": true,
"value": "www.example.com",
"key": null,
"project_id": "e3cd678b11784734bc366148aa37580e",
"type": "HOST_NAME",
"id": "d24521a0-df84-4468-861a-a531af116d1e"
}
]
}
`
// HandleRuleListSuccessfully sets up the test server to respond to a rule List request.
func HandleRuleListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, RulesListBody)
case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab":
fmt.Fprintf(w, `{ "rules": [] }`)
default:
t.Fatalf("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules invoked with unexpected marker=[%s]", marker)
}
})
}
// HandleRuleGetSuccessfully sets up the test server to respond to a rule Get request.
func HandleRuleGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules/16621dbb-a736-4888-a57a-3ecd53df784c", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
fmt.Fprintf(w, SingleRuleBody)
})
}
// HandleRuleDeletionSuccessfully sets up the test server to respond to a rule deletion request.
func HandleRuleDeletionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules/16621dbb-a736-4888-a57a-3ecd53df784c", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
}
// PostUpdateRuleBody is the canned response body of a Update request on an existing rule.
const PostUpdateRuleBody = `
{
"rule": {
"compare_type": "REGEX",
"invert": false,
"admin_state_up": true,
"value": "/images/special*",
"key": null,
"project_id": "e3cd678b11784734bc366148aa37580e",
"type": "PATH",
"id": "16621dbb-a736-4888-a57a-3ecd53df784c"
}
}
`
// HandleRuleUpdateSuccessfully sets up the test server to respond to a rule Update request.
func HandleRuleUpdateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd/rules/16621dbb-a736-4888-a57a-3ecd53df784c", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestJSONRequest(t, r, `{
"rule": {
"compare_type": "REGEX",
"invert": false,
"key": null,
"type": "PATH",
"value": "/images/special*"
}
}`)
fmt.Fprintf(w, PostUpdateRuleBody)
})
}