blob: 4339a16d4404e9e108b6c07afc9713f06fd864b4 [file] [log] [blame]
Ash Wilsone77ffb02014-10-20 13:10:26 -04001// +build fixtures
Ash Wilson15e0f272014-10-21 15:33:02 -04002
Ash Wilsone77ffb02014-10-20 13:10:26 -04003package servers
4
Ash Wilson664fe332014-10-21 17:47:49 -04005import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 th "github.com/rackspace/gophercloud/testhelper"
11 "github.com/rackspace/gophercloud/testhelper/client"
12)
13
Ash Wilsone77ffb02014-10-20 13:10:26 -040014// ServerListBody contains the canned body of a servers.List response.
15const ServerListBody = `
16{
17 "servers": [
18 {
19 "status": "ACTIVE",
20 "updated": "2014-09-25T13:10:10Z",
21 "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
22 "OS-EXT-SRV-ATTR:host": "devstack",
23 "addresses": {
24 "private": [
25 {
26 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
27 "version": 4,
28 "addr": "10.0.0.32",
29 "OS-EXT-IPS:type": "fixed"
30 }
31 ]
32 },
33 "links": [
34 {
35 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
36 "rel": "self"
37 },
38 {
39 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
40 "rel": "bookmark"
41 }
42 ],
43 "key_name": null,
44 "image": {
45 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
46 "links": [
47 {
48 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
49 "rel": "bookmark"
50 }
51 ]
52 },
53 "OS-EXT-STS:task_state": null,
54 "OS-EXT-STS:vm_state": "active",
55 "OS-EXT-SRV-ATTR:instance_name": "instance-0000001e",
56 "OS-SRV-USG:launched_at": "2014-09-25T13:10:10.000000",
57 "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
58 "flavor": {
59 "id": "1",
60 "links": [
61 {
62 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
63 "rel": "bookmark"
64 }
65 ]
66 },
67 "id": "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
68 "security_groups": [
69 {
70 "name": "default"
71 }
72 ],
73 "OS-SRV-USG:terminated_at": null,
74 "OS-EXT-AZ:availability_zone": "nova",
75 "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
76 "name": "herp",
77 "created": "2014-09-25T13:10:02Z",
78 "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
79 "OS-DCF:diskConfig": "MANUAL",
80 "os-extended-volumes:volumes_attached": [],
81 "accessIPv4": "",
82 "accessIPv6": "",
83 "progress": 0,
84 "OS-EXT-STS:power_state": 1,
85 "config_drive": "",
86 "metadata": {}
87 },
88 {
89 "status": "ACTIVE",
90 "updated": "2014-09-25T13:04:49Z",
91 "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
92 "OS-EXT-SRV-ATTR:host": "devstack",
93 "addresses": {
94 "private": [
95 {
96 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
97 "version": 4,
98 "addr": "10.0.0.31",
99 "OS-EXT-IPS:type": "fixed"
100 }
101 ]
102 },
103 "links": [
104 {
105 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
106 "rel": "self"
107 },
108 {
109 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
110 "rel": "bookmark"
111 }
112 ],
113 "key_name": null,
114 "image": {
115 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
116 "links": [
117 {
118 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
119 "rel": "bookmark"
120 }
121 ]
122 },
123 "OS-EXT-STS:task_state": null,
124 "OS-EXT-STS:vm_state": "active",
125 "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d",
126 "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
127 "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
128 "flavor": {
129 "id": "1",
130 "links": [
131 {
132 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
133 "rel": "bookmark"
134 }
135 ]
136 },
137 "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
138 "security_groups": [
139 {
140 "name": "default"
141 }
142 ],
143 "OS-SRV-USG:terminated_at": null,
144 "OS-EXT-AZ:availability_zone": "nova",
145 "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
146 "name": "derp",
147 "created": "2014-09-25T13:04:41Z",
148 "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
149 "OS-DCF:diskConfig": "MANUAL",
150 "os-extended-volumes:volumes_attached": [],
151 "accessIPv4": "",
152 "accessIPv6": "",
153 "progress": 0,
154 "OS-EXT-STS:power_state": 1,
155 "config_drive": "",
156 "metadata": {}
157 }
158 ]
159}
160`
161
162// SingleServerBody is the canned body of a Get request on an existing server.
163const SingleServerBody = `
164{
165 "server": {
166 "status": "ACTIVE",
167 "updated": "2014-09-25T13:04:49Z",
168 "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
169 "OS-EXT-SRV-ATTR:host": "devstack",
170 "addresses": {
171 "private": [
172 {
173 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
174 "version": 4,
175 "addr": "10.0.0.31",
176 "OS-EXT-IPS:type": "fixed"
177 }
178 ]
179 },
180 "links": [
181 {
182 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
183 "rel": "self"
184 },
185 {
186 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
187 "rel": "bookmark"
188 }
189 ],
190 "key_name": null,
191 "image": {
192 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
193 "links": [
194 {
195 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
196 "rel": "bookmark"
197 }
198 ]
199 },
200 "OS-EXT-STS:task_state": null,
201 "OS-EXT-STS:vm_state": "active",
202 "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d",
203 "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
204 "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
205 "flavor": {
206 "id": "1",
207 "links": [
208 {
209 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
210 "rel": "bookmark"
211 }
212 ]
213 },
214 "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
215 "security_groups": [
216 {
217 "name": "default"
218 }
219 ],
220 "OS-SRV-USG:terminated_at": null,
221 "OS-EXT-AZ:availability_zone": "nova",
222 "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
223 "name": "derp",
224 "created": "2014-09-25T13:04:41Z",
225 "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
226 "OS-DCF:diskConfig": "MANUAL",
227 "os-extended-volumes:volumes_attached": [],
228 "accessIPv4": "",
229 "accessIPv6": "",
230 "progress": 0,
231 "OS-EXT-STS:power_state": 1,
232 "config_drive": "",
233 "metadata": {}
234 }
235}
236`
237
238var (
239 // ServerHerp is a Server struct that should correspond to the first result in ServerListBody.
240 ServerHerp = Server{
241 Status: "ACTIVE",
242 Updated: "2014-09-25T13:10:10Z",
243 HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
244 Addresses: map[string]interface{}{
245 "private": []interface{}{
246 map[string]interface{}{
247 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
248 "version": float64(4),
249 "addr": "10.0.0.32",
250 "OS-EXT-IPS:type": "fixed",
251 },
252 },
253 },
254 Links: []interface{}{
255 map[string]interface{}{
256 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
257 "rel": "self",
258 },
259 map[string]interface{}{
260 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
261 "rel": "bookmark",
262 },
263 },
264 Image: map[string]interface{}{
265 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
266 "links": []interface{}{
267 map[string]interface{}{
268 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
269 "rel": "bookmark",
270 },
271 },
272 },
273 Flavor: map[string]interface{}{
274 "id": "1",
275 "links": []interface{}{
276 map[string]interface{}{
277 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
278 "rel": "bookmark",
279 },
280 },
281 },
282 ID: "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
283 UserID: "9349aff8be7545ac9d2f1d00999a23cd",
284 Name: "herp",
285 Created: "2014-09-25T13:10:02Z",
286 TenantID: "fcad67a6189847c4aecfa3c81a05783b",
287 Metadata: map[string]interface{}{},
Joe Topjian978bb502015-02-12 20:55:31 +0000288 SecurityGroups: []map[string]interface{}{
289 map[string]interface{}{
290 "name": "default",
291 },
292 },
Ash Wilsone77ffb02014-10-20 13:10:26 -0400293 }
294
295 // ServerDerp is a Server struct that should correspond to the second server in ServerListBody.
296 ServerDerp = Server{
297 Status: "ACTIVE",
298 Updated: "2014-09-25T13:04:49Z",
299 HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
300 Addresses: map[string]interface{}{
301 "private": []interface{}{
302 map[string]interface{}{
303 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
304 "version": float64(4),
305 "addr": "10.0.0.31",
306 "OS-EXT-IPS:type": "fixed",
307 },
308 },
309 },
310 Links: []interface{}{
311 map[string]interface{}{
312 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
313 "rel": "self",
314 },
315 map[string]interface{}{
316 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
317 "rel": "bookmark",
318 },
319 },
320 Image: map[string]interface{}{
321 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
322 "links": []interface{}{
323 map[string]interface{}{
324 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
325 "rel": "bookmark",
326 },
327 },
328 },
329 Flavor: map[string]interface{}{
330 "id": "1",
331 "links": []interface{}{
332 map[string]interface{}{
333 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
334 "rel": "bookmark",
335 },
336 },
337 },
338 ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
339 UserID: "9349aff8be7545ac9d2f1d00999a23cd",
340 Name: "derp",
341 Created: "2014-09-25T13:04:41Z",
342 TenantID: "fcad67a6189847c4aecfa3c81a05783b",
343 Metadata: map[string]interface{}{},
Joe Topjian978bb502015-02-12 20:55:31 +0000344 SecurityGroups: []map[string]interface{}{
345 map[string]interface{}{
346 "name": "default",
347 },
348 },
Ash Wilsone77ffb02014-10-20 13:10:26 -0400349 }
350)
Ash Wilson664fe332014-10-21 17:47:49 -0400351
352// HandleServerCreationSuccessfully sets up the test server to respond to a server creation request
353// with a given response.
354func HandleServerCreationSuccessfully(t *testing.T, response string) {
355 th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
356 th.TestMethod(t, r, "POST")
357 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
358 th.TestJSONRequest(t, r, `{
359 "server": {
360 "name": "derp",
361 "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb",
362 "flavorRef": "1"
363 }
364 }`)
365
366 w.WriteHeader(http.StatusAccepted)
367 w.Header().Add("Content-Type", "application/json")
368 fmt.Fprintf(w, response)
369 })
370}
371
Ash Wilsona70510a2014-10-23 11:54:03 -0400372// HandleServerListSuccessfully sets up the test server to respond to a server List request.
373func HandleServerListSuccessfully(t *testing.T) {
374 th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
375 th.TestMethod(t, r, "GET")
376 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
377
378 w.Header().Add("Content-Type", "application/json")
379 r.ParseForm()
380 marker := r.Form.Get("marker")
381 switch marker {
382 case "":
383 fmt.Fprintf(w, ServerListBody)
384 case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
385 fmt.Fprintf(w, `{ "servers": [] }`)
386 default:
387 t.Fatalf("/servers/detail invoked with unexpected marker=[%s]", marker)
388 }
389 })
390}
391
Ash Wilson664fe332014-10-21 17:47:49 -0400392// HandleServerDeletionSuccessfully sets up the test server to respond to a server deletion request.
393func HandleServerDeletionSuccessfully(t *testing.T) {
394 th.Mux.HandleFunc("/servers/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
395 th.TestMethod(t, r, "DELETE")
396 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
397
398 w.WriteHeader(http.StatusNoContent)
399 })
400}
Ash Wilson1c1eb882014-10-21 18:14:31 -0400401
Ash Wilson189c95c2014-10-23 11:41:35 -0400402// HandleServerGetSuccessfully sets up the test server to respond to a server Get request.
403func HandleServerGetSuccessfully(t *testing.T) {
404 th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
405 th.TestMethod(t, r, "GET")
406 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
407 th.TestHeader(t, r, "Accept", "application/json")
408
409 fmt.Fprintf(w, SingleServerBody)
410 })
411}
412
413// HandleServerUpdateSuccessfully sets up the test server to respond to a server Update request.
414func HandleServerUpdateSuccessfully(t *testing.T) {
415 th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
416 th.TestMethod(t, r, "PUT")
417 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
418 th.TestHeader(t, r, "Accept", "application/json")
419 th.TestHeader(t, r, "Content-Type", "application/json")
420 th.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`)
421
422 fmt.Fprintf(w, SingleServerBody)
423 })
424}
425
Ash Wilson1c1eb882014-10-21 18:14:31 -0400426// HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password
427// change request.
428func HandleAdminPasswordChangeSuccessfully(t *testing.T) {
429 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
430 th.TestMethod(t, r, "POST")
431 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
432 th.TestJSONRequest(t, r, `{ "changePassword": { "adminPass": "new-password" } }`)
433
434 w.WriteHeader(http.StatusAccepted)
435 })
436}
Ash Wilson2295ba52014-10-21 18:19:28 -0400437
438// HandleRebootSuccessfully sets up the test server to respond to a reboot request with success.
439func HandleRebootSuccessfully(t *testing.T) {
440 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
441 th.TestMethod(t, r, "POST")
442 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
443 th.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`)
444
445 w.WriteHeader(http.StatusAccepted)
446 })
447}
Ash Wilsonacf49c62014-10-21 18:25:11 -0400448
449// HandleRebuildSuccessfully sets up the test server to respond to a rebuild request with success.
450func HandleRebuildSuccessfully(t *testing.T, response string) {
451 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
452 th.TestMethod(t, r, "POST")
453 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
454 th.TestJSONRequest(t, r, `
455 {
456 "rebuild": {
457 "name": "new-name",
458 "adminPass": "swordfish",
459 "imageRef": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
460 "accessIPv4": "1.2.3.4"
461 }
462 }
463 `)
464
465 w.WriteHeader(http.StatusAccepted)
466 w.Header().Add("Content-Type", "application/json")
467 fmt.Fprintf(w, response)
468 })
469}
Alex Gaynorfa8fbeb2014-11-13 13:39:31 -0800470
Jon Perrittcc77da62014-11-16 13:14:21 -0700471// HandleServerRescueSuccessfully sets up the test server to respond to a server Rescue request.
Alex Gaynorfa8fbeb2014-11-13 13:39:31 -0800472func HandleServerRescueSuccessfully(t *testing.T) {
473 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
474 th.TestMethod(t, r, "POST")
475 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
476 th.TestJSONRequest(t, r, `{ "rescue": { "adminPass": "1234567890" } }`)
477
478 w.WriteHeader(http.StatusOK)
479 w.Write([]byte(`{ "adminPass": "1234567890" }`))
480 })
481}
Jon Perrittcc77da62014-11-16 13:14:21 -0700482
Jon Perritt78c57ce2014-11-20 11:07:18 -0700483// HandleMetadatumGetSuccessfully sets up the test server to respond to a metadatum Get request.
484func HandleMetadatumGetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700485 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
486 th.TestMethod(t, r, "GET")
487 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
488 th.TestHeader(t, r, "Accept", "application/json")
489
490 w.WriteHeader(http.StatusOK)
491 w.Header().Add("Content-Type", "application/json")
492 w.Write([]byte(`{ "meta": {"foo":"bar"}}`))
493 })
494}
495
Jon Perritt78c57ce2014-11-20 11:07:18 -0700496// HandleMetadatumCreateSuccessfully sets up the test server to respond to a metadatum Create request.
497func HandleMetadatumCreateSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700498 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
499 th.TestMethod(t, r, "PUT")
500 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
501 th.TestJSONRequest(t, r, `{
502 "meta": {
503 "foo": "bar"
504 }
505 }`)
506
507 w.WriteHeader(http.StatusOK)
508 w.Header().Add("Content-Type", "application/json")
509 w.Write([]byte(`{ "meta": {"foo":"bar"}}`))
510 })
511}
512
Jon Perritt78c57ce2014-11-20 11:07:18 -0700513// HandleMetadatumDeleteSuccessfully sets up the test server to respond to a metadatum Delete request.
514func HandleMetadatumDeleteSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700515 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
516 th.TestMethod(t, r, "DELETE")
517 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
518
519 w.WriteHeader(http.StatusNoContent)
520 })
521}
522
Jon Perritt78c57ce2014-11-20 11:07:18 -0700523// HandleMetadataGetSuccessfully sets up the test server to respond to a metadata Get request.
524func HandleMetadataGetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700525 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
526 th.TestMethod(t, r, "GET")
527 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
528 th.TestHeader(t, r, "Accept", "application/json")
529
530 w.WriteHeader(http.StatusOK)
531 w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`))
532 })
533}
534
Jon Perritt789f8322014-11-21 08:20:04 -0700535// HandleMetadataResetSuccessfully sets up the test server to respond to a metadata Create request.
536func HandleMetadataResetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700537 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
538 th.TestMethod(t, r, "PUT")
539 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
540 th.TestJSONRequest(t, r, `{
541 "metadata": {
542 "foo": "bar",
543 "this": "that"
544 }
545 }`)
546
547 w.WriteHeader(http.StatusOK)
548 w.Header().Add("Content-Type", "application/json")
549 w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`))
550 })
551}
552
Jon Perritt78c57ce2014-11-20 11:07:18 -0700553// HandleMetadataUpdateSuccessfully sets up the test server to respond to a metadata Update request.
554func HandleMetadataUpdateSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700555 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
556 th.TestMethod(t, r, "POST")
557 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
558 th.TestJSONRequest(t, r, `{
559 "metadata": {
560 "foo": "baz",
561 "this": "those"
562 }
563 }`)
564
565 w.WriteHeader(http.StatusOK)
566 w.Header().Add("Content-Type", "application/json")
567 w.Write([]byte(`{ "metadata": {"foo":"baz", "this":"those"}}`))
568 })
569}
Jon Perritt5cb49482015-02-19 12:19:58 -0700570
571// ListAddressesExpected represents an expected repsonse from a ListAddresses request.
572var ListAddressesExpected = map[string][]Address{
573 "public": []Address{
574 Address{
575 Version: 4,
576 Address: "80.56.136.39",
577 },
578 Address{
579 Version: 6,
580 Address: "2001:4800:790e:510:be76:4eff:fe04:82a8",
581 },
582 },
583 "private": []Address{
584 Address{
585 Version: 4,
586 Address: "10.880.3.154",
587 },
588 },
589}
590
591// HandleAddressListSuccessfully sets up the test server to respond to a ListAddresses request.
592func HandleAddressListSuccessfully(t *testing.T) {
593 th.Mux.HandleFunc("/servers/asdfasdfasdf/ips", func(w http.ResponseWriter, r *http.Request) {
594 th.TestMethod(t, r, "GET")
595 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
596
597 w.Header().Add("Content-Type", "application/json")
598 fmt.Fprintf(w, `{
599 "addresses": {
600 "public": [
601 {
602 "version": 4,
603 "addr": "50.56.176.35"
604 },
605 {
606 "version": 6,
607 "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8"
608 }
609 ],
610 "private": [
611 {
612 "version": 4,
613 "addr": "10.180.3.155"
614 }
615 ]
616 }
617 }`)
618 })
619}
Jon Perritt04d073c2015-02-19 21:46:23 -0700620
621// ListNetworkAddressesExpected represents an expected repsonse from a ListAddressesByNetwork request.
Jon Perrittb51ba9c2015-02-23 10:56:35 -0700622var ListNetworkAddressesExpected = []Address{
623 Address{
624 Version: 4,
625 Address: "50.56.176.35",
626 },
627 Address{
628 Version: 6,
629 Address: "2001:4800:780e:510:be76:4eff:fe04:84a8",
Jon Perritt04d073c2015-02-19 21:46:23 -0700630 },
631}
632
633// HandleNetworkAddressListSuccessfully sets up the test server to respond to a ListAddressesByNetwork request.
634func HandleNetworkAddressListSuccessfully(t *testing.T) {
635 th.Mux.HandleFunc("/servers/asdfasdfasdf/ips/public", func(w http.ResponseWriter, r *http.Request) {
636 th.TestMethod(t, r, "GET")
637 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
638
639 w.Header().Add("Content-Type", "application/json")
640 fmt.Fprintf(w, `{
641 "public": [
642 {
643 "version": 4,
644 "addr": "50.56.176.35"
645 },
646 {
647 "version": 6,
648 "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8"
649 }
650 ]
651 }`)
652 })
653}
einarf2fc665e2015-04-16 20:16:21 +0000654
655// HandleCreateServerImageSuccessfully sets up the test server to respond to a TestCreateServerImage request.
656func HandleCreateServerImageSuccessfully(t *testing.T) {
657 th.Mux.HandleFunc("/servers/serverimage/action", func(w http.ResponseWriter, r *http.Request) {
658 th.TestMethod(t, r, "POST")
659 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
660 w.Header().Add("Location", "https://0.0.0.0/images/xxxx-xxxxx-xxxxx-xxxx")
661 w.WriteHeader(http.StatusAccepted)
662 })
663}
664