forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
440 lines (409 loc) · 15.5 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
package testing
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources"
th "github.com/gophercloud/gophercloud/testhelper"
fake "github.com/gophercloud/gophercloud/testhelper/client"
)
// FindExpected represents the expected object from a Find request.
var FindExpected = []stackresources.Resource{
{
Name: "hello_world",
Links: []gophercloud.Link{
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
Rel: "self",
},
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
Rel: "stack",
},
},
LogicalID: "hello_world",
StatusReason: "state changed",
UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
RequiredBy: []interface{}{},
Status: "CREATE_IN_PROGRESS",
PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
Type: "OS::Nova::Server",
Attributes: map[string]interface{}{"SXSW": "atx"},
Description: "Some resource",
},
}
// FindOutput represents the response body from a Find request.
const FindOutput = `
{
"resources": [
{
"description": "Some resource",
"attributes": {"SXSW": "atx"},
"resource_name": "hello_world",
"links": [
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
"rel": "self"
},
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
"rel": "stack"
}
],
"logical_resource_id": "hello_world",
"resource_status_reason": "state changed",
"updated_time": "2015-02-05T21:33:11",
"creation_time": "2015-02-05T21:33:10",
"required_by": [],
"resource_status": "CREATE_IN_PROGRESS",
"physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
"resource_type": "OS::Nova::Server"
}
]
}`
// HandleFindSuccessfully creates an HTTP handler at `/stacks/hello_world/resources`
// on the test handler mux that responds with a `Find` response.
func HandleFindSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, output)
})
}
// ListExpected represents the expected object from a List request.
var ListExpected = []stackresources.Resource{
{
Name: "hello_world",
Links: []gophercloud.Link{
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
Rel: "self",
},
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
Rel: "stack",
},
},
LogicalID: "hello_world",
StatusReason: "state changed",
UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
RequiredBy: []interface{}{},
Status: "CREATE_IN_PROGRESS",
PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
Type: "OS::Nova::Server",
Attributes: map[string]interface{}{"SXSW": "atx"},
Description: "Some resource",
},
}
// ListOutput represents the response body from a List request.
const ListOutput = `{
"resources": [
{
"resource_name": "hello_world",
"links": [
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
"rel": "self"
},
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
"rel": "stack"
}
],
"logical_resource_id": "hello_world",
"resource_status_reason": "state changed",
"updated_time": "2015-02-05T21:33:11",
"required_by": [],
"resource_status": "CREATE_IN_PROGRESS",
"physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
"creation_time": "2015-02-05T21:33:10",
"resource_type": "OS::Nova::Server",
"attributes": {"SXSW": "atx"},
"description": "Some resource"
}
]
}`
// HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources`
// on the test handler mux that responds with a `List` response.
func HandleListSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, output)
case "49181cd6-169a-4130-9455-31185bbfc5bf":
fmt.Fprintf(w, `{"resources":[]}`)
default:
t.Fatalf("Unexpected marker: [%s]", marker)
}
})
}
// GetExpected represents the expected object from a Get request.
var GetExpected = &stackresources.Resource{
Name: "wordpress_instance",
Links: []gophercloud.Link{
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance",
Rel: "self",
},
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e",
Rel: "stack",
},
},
LogicalID: "wordpress_instance",
Attributes: map[string]interface{}{"SXSW": "atx"},
StatusReason: "state changed",
UpdatedTime: time.Date(2014, 12, 10, 18, 34, 35, 0, time.UTC),
RequiredBy: []interface{}{},
Status: "CREATE_COMPLETE",
PhysicalID: "00e3a2fe-c65d-403c-9483-4db9930dd194",
Type: "OS::Nova::Server",
}
// GetOutput represents the response body from a Get request.
const GetOutput = `
{
"resource": {
"description": "Some resource",
"attributes": {"SXSW": "atx"},
"resource_name": "wordpress_instance",
"description": "",
"links": [
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance",
"rel": "self"
},
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e",
"rel": "stack"
}
],
"logical_resource_id": "wordpress_instance",
"resource_status": "CREATE_COMPLETE",
"updated_time": "2014-12-10T18:34:35",
"required_by": [],
"resource_status_reason": "state changed",
"physical_resource_id": "00e3a2fe-c65d-403c-9483-4db9930dd194",
"resource_type": "OS::Nova::Server"
}
}`
// HandleGetSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance`
// on the test handler mux that responds with a `Get` response.
func HandleGetSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, output)
})
}
// MetadataExpected represents the expected object from a Metadata request.
var MetadataExpected = map[string]string{
"number": "7",
"animal": "auk",
}
// MetadataOutput represents the response body from a Metadata request.
const MetadataOutput = `
{
"metadata": {
"number": "7",
"animal": "auk"
}
}`
// HandleMetadataSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata`
// on the test handler mux that responds with a `Metadata` response.
func HandleMetadataSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, output)
})
}
// ListTypesExpected represents the expected object from a ListTypes request.
var ListTypesExpected = stackresources.ResourceTypes{
"OS::Nova::Server",
"OS::Heat::RandomString",
"OS::Swift::Container",
"OS::Trove::Instance",
"OS::Nova::FloatingIPAssociation",
"OS::Cinder::VolumeAttachment",
"OS::Nova::FloatingIP",
"OS::Nova::KeyPair",
}
// same as above, but sorted
var SortedListTypesExpected = stackresources.ResourceTypes{
"OS::Cinder::VolumeAttachment",
"OS::Heat::RandomString",
"OS::Nova::FloatingIP",
"OS::Nova::FloatingIPAssociation",
"OS::Nova::KeyPair",
"OS::Nova::Server",
"OS::Swift::Container",
"OS::Trove::Instance",
}
// ListTypesOutput represents the response body from a ListTypes request.
const ListTypesOutput = `
{
"resource_types": [
"OS::Nova::Server",
"OS::Heat::RandomString",
"OS::Swift::Container",
"OS::Trove::Instance",
"OS::Nova::FloatingIPAssociation",
"OS::Cinder::VolumeAttachment",
"OS::Nova::FloatingIP",
"OS::Nova::KeyPair"
]
}`
// HandleListTypesSuccessfully creates an HTTP handler at `/resource_types`
// on the test handler mux that responds with a `ListTypes` response.
func HandleListTypesSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/resource_types", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, output)
})
}
// GetSchemaExpected represents the expected object from a Schema request.
var GetSchemaExpected = &stackresources.TypeSchema{
Attributes: map[string]interface{}{
"an_attribute": map[string]interface{}{
"description": "An attribute description .",
},
},
Properties: map[string]interface{}{
"a_property": map[string]interface{}{
"update_allowed": false,
"required": true,
"type": "string",
"description": "A resource description.",
},
},
ResourceType: "OS::Heat::AResourceName",
SupportStatus: map[string]interface{}{
"message": "A status message",
"status": "SUPPORTED",
"version": "2014.1",
},
}
// GetSchemaOutput represents the response body from a Schema request.
const GetSchemaOutput = `
{
"attributes": {
"an_attribute": {
"description": "An attribute description ."
}
},
"properties": {
"a_property": {
"update_allowed": false,
"required": true,
"type": "string",
"description": "A resource description."
}
},
"resource_type": "OS::Heat::AResourceName",
"support_status": {
"message": "A status message",
"status": "SUPPORTED",
"version": "2014.1"
}
}`
// HandleGetSchemaSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName`
// on the test handler mux that responds with a `Schema` response.
func HandleGetSchemaSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, output)
})
}
// GetTemplateExpected represents the expected object from a Template request.
var GetTemplateExpected = "{\n \"HeatTemplateFormatVersion\": \"2012-12-12\",\n \"Outputs\": {\n \"private_key\": {\n \"Description\": \"The private key if it has been saved.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"private_key\\\"]}\"\n },\n \"public_key\": {\n \"Description\": \"The public key.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"public_key\\\"]}\"\n }\n },\n \"Parameters\": {\n \"name\": {\n \"Description\": \"The name of the key pair.\",\n \"Type\": \"String\"\n },\n \"public_key\": {\n \"Description\": \"The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.\",\n \"Type\": \"String\"\n },\n \"save_private_key\": {\n \"AllowedValues\": [\n \"True\",\n \"true\",\n \"False\",\n \"false\"\n ],\n \"Default\": false,\n \"Description\": \"True if the system should remember a generated private key; False otherwise.\",\n \"Type\": \"String\"\n }\n },\n \"Resources\": {\n \"KeyPair\": {\n \"Properties\": {\n \"name\": {\n \"Ref\": \"name\"\n },\n \"public_key\": {\n \"Ref\": \"public_key\"\n },\n \"save_private_key\": {\n \"Ref\": \"save_private_key\"\n }\n },\n \"Type\": \"OS::Nova::KeyPair\"\n }\n }\n}"
// GetTemplateOutput represents the response body from a Template request.
const GetTemplateOutput = `
{
"HeatTemplateFormatVersion": "2012-12-12",
"Outputs": {
"private_key": {
"Description": "The private key if it has been saved.",
"Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}"
},
"public_key": {
"Description": "The public key.",
"Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}"
}
},
"Parameters": {
"name": {
"Description": "The name of the key pair.",
"Type": "String"
},
"public_key": {
"Description": "The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.",
"Type": "String"
},
"save_private_key": {
"AllowedValues": [
"True",
"true",
"False",
"false"
],
"Default": false,
"Description": "True if the system should remember a generated private key; False otherwise.",
"Type": "String"
}
},
"Resources": {
"KeyPair": {
"Properties": {
"name": {
"Ref": "name"
},
"public_key": {
"Ref": "public_key"
},
"save_private_key": {
"Ref": "save_private_key"
}
},
"Type": "OS::Nova::KeyPair"
}
}
}`
// HandleGetTemplateSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName/template`
// on the test handler mux that responds with a `Template` response.
func HandleGetTemplateSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName/template", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, output)
})
}