blob: 01646058e6f7ce6e7ea682fb85c165c1001fdba4 [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{}{},
288 }
289
290 // ServerDerp is a Server struct that should correspond to the second server in ServerListBody.
291 ServerDerp = Server{
292 Status: "ACTIVE",
293 Updated: "2014-09-25T13:04:49Z",
294 HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
295 Addresses: map[string]interface{}{
296 "private": []interface{}{
297 map[string]interface{}{
298 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
299 "version": float64(4),
300 "addr": "10.0.0.31",
301 "OS-EXT-IPS:type": "fixed",
302 },
303 },
304 },
305 Links: []interface{}{
306 map[string]interface{}{
307 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
308 "rel": "self",
309 },
310 map[string]interface{}{
311 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
312 "rel": "bookmark",
313 },
314 },
315 Image: map[string]interface{}{
316 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
317 "links": []interface{}{
318 map[string]interface{}{
319 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
320 "rel": "bookmark",
321 },
322 },
323 },
324 Flavor: map[string]interface{}{
325 "id": "1",
326 "links": []interface{}{
327 map[string]interface{}{
328 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
329 "rel": "bookmark",
330 },
331 },
332 },
333 ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
334 UserID: "9349aff8be7545ac9d2f1d00999a23cd",
335 Name: "derp",
336 Created: "2014-09-25T13:04:41Z",
337 TenantID: "fcad67a6189847c4aecfa3c81a05783b",
338 Metadata: map[string]interface{}{},
339 }
340)
Ash Wilson664fe332014-10-21 17:47:49 -0400341
342// HandleServerCreationSuccessfully sets up the test server to respond to a server creation request
343// with a given response.
344func HandleServerCreationSuccessfully(t *testing.T, response string) {
345 th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
346 th.TestMethod(t, r, "POST")
347 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
348 th.TestJSONRequest(t, r, `{
349 "server": {
350 "name": "derp",
351 "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb",
352 "flavorRef": "1"
353 }
354 }`)
355
356 w.WriteHeader(http.StatusAccepted)
357 w.Header().Add("Content-Type", "application/json")
358 fmt.Fprintf(w, response)
359 })
360}
361
Ash Wilsona70510a2014-10-23 11:54:03 -0400362// HandleServerListSuccessfully sets up the test server to respond to a server List request.
363func HandleServerListSuccessfully(t *testing.T) {
364 th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
365 th.TestMethod(t, r, "GET")
366 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
367
368 w.Header().Add("Content-Type", "application/json")
369 r.ParseForm()
370 marker := r.Form.Get("marker")
371 switch marker {
372 case "":
373 fmt.Fprintf(w, ServerListBody)
374 case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
375 fmt.Fprintf(w, `{ "servers": [] }`)
376 default:
377 t.Fatalf("/servers/detail invoked with unexpected marker=[%s]", marker)
378 }
379 })
380}
381
Ash Wilson664fe332014-10-21 17:47:49 -0400382// HandleServerDeletionSuccessfully sets up the test server to respond to a server deletion request.
383func HandleServerDeletionSuccessfully(t *testing.T) {
384 th.Mux.HandleFunc("/servers/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
385 th.TestMethod(t, r, "DELETE")
386 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
387
388 w.WriteHeader(http.StatusNoContent)
389 })
390}
Ash Wilson1c1eb882014-10-21 18:14:31 -0400391
Ash Wilson189c95c2014-10-23 11:41:35 -0400392// HandleServerGetSuccessfully sets up the test server to respond to a server Get request.
393func HandleServerGetSuccessfully(t *testing.T) {
394 th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
395 th.TestMethod(t, r, "GET")
396 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
397 th.TestHeader(t, r, "Accept", "application/json")
398
399 fmt.Fprintf(w, SingleServerBody)
400 })
401}
402
403// HandleServerUpdateSuccessfully sets up the test server to respond to a server Update request.
404func HandleServerUpdateSuccessfully(t *testing.T) {
405 th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
406 th.TestMethod(t, r, "PUT")
407 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
408 th.TestHeader(t, r, "Accept", "application/json")
409 th.TestHeader(t, r, "Content-Type", "application/json")
410 th.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`)
411
412 fmt.Fprintf(w, SingleServerBody)
413 })
414}
415
Ash Wilson1c1eb882014-10-21 18:14:31 -0400416// HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password
417// change request.
418func HandleAdminPasswordChangeSuccessfully(t *testing.T) {
419 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
420 th.TestMethod(t, r, "POST")
421 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
422 th.TestJSONRequest(t, r, `{ "changePassword": { "adminPass": "new-password" } }`)
423
424 w.WriteHeader(http.StatusAccepted)
425 })
426}
Ash Wilson2295ba52014-10-21 18:19:28 -0400427
428// HandleRebootSuccessfully sets up the test server to respond to a reboot request with success.
429func HandleRebootSuccessfully(t *testing.T) {
430 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
431 th.TestMethod(t, r, "POST")
432 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
433 th.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`)
434
435 w.WriteHeader(http.StatusAccepted)
436 })
437}
Ash Wilsonacf49c62014-10-21 18:25:11 -0400438
439// HandleRebuildSuccessfully sets up the test server to respond to a rebuild request with success.
440func HandleRebuildSuccessfully(t *testing.T, response string) {
441 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
442 th.TestMethod(t, r, "POST")
443 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
444 th.TestJSONRequest(t, r, `
445 {
446 "rebuild": {
447 "name": "new-name",
448 "adminPass": "swordfish",
449 "imageRef": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
450 "accessIPv4": "1.2.3.4"
451 }
452 }
453 `)
454
455 w.WriteHeader(http.StatusAccepted)
456 w.Header().Add("Content-Type", "application/json")
457 fmt.Fprintf(w, response)
458 })
459}
Alex Gaynorfa8fbeb2014-11-13 13:39:31 -0800460
Jon Perrittcc77da62014-11-16 13:14:21 -0700461// HandleServerRescueSuccessfully sets up the test server to respond to a server Rescue request.
Alex Gaynorfa8fbeb2014-11-13 13:39:31 -0800462func HandleServerRescueSuccessfully(t *testing.T) {
463 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
464 th.TestMethod(t, r, "POST")
465 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
466 th.TestJSONRequest(t, r, `{ "rescue": { "adminPass": "1234567890" } }`)
467
468 w.WriteHeader(http.StatusOK)
469 w.Write([]byte(`{ "adminPass": "1234567890" }`))
470 })
471}
Jon Perrittcc77da62014-11-16 13:14:21 -0700472
Jon Perritt78c57ce2014-11-20 11:07:18 -0700473// HandleMetadatumGetSuccessfully sets up the test server to respond to a metadatum Get request.
474func HandleMetadatumGetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700475 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
476 th.TestMethod(t, r, "GET")
477 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
478 th.TestHeader(t, r, "Accept", "application/json")
479
480 w.WriteHeader(http.StatusOK)
481 w.Header().Add("Content-Type", "application/json")
482 w.Write([]byte(`{ "meta": {"foo":"bar"}}`))
483 })
484}
485
Jon Perritt78c57ce2014-11-20 11:07:18 -0700486// HandleMetadatumCreateSuccessfully sets up the test server to respond to a metadatum Create request.
487func HandleMetadatumCreateSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700488 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
489 th.TestMethod(t, r, "PUT")
490 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
491 th.TestJSONRequest(t, r, `{
492 "meta": {
493 "foo": "bar"
494 }
495 }`)
496
497 w.WriteHeader(http.StatusOK)
498 w.Header().Add("Content-Type", "application/json")
499 w.Write([]byte(`{ "meta": {"foo":"bar"}}`))
500 })
501}
502
Jon Perritt78c57ce2014-11-20 11:07:18 -0700503// HandleMetadatumDeleteSuccessfully sets up the test server to respond to a metadatum Delete request.
504func HandleMetadatumDeleteSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700505 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
506 th.TestMethod(t, r, "DELETE")
507 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
508
509 w.WriteHeader(http.StatusNoContent)
510 })
511}
512
Jon Perritt78c57ce2014-11-20 11:07:18 -0700513// HandleMetadataGetSuccessfully sets up the test server to respond to a metadata Get request.
514func HandleMetadataGetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700515 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
516 th.TestMethod(t, r, "GET")
517 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
518 th.TestHeader(t, r, "Accept", "application/json")
519
520 w.WriteHeader(http.StatusOK)
521 w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`))
522 })
523}
524
Jon Perritt789f8322014-11-21 08:20:04 -0700525// HandleMetadataResetSuccessfully sets up the test server to respond to a metadata Create request.
526func HandleMetadataResetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700527 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
528 th.TestMethod(t, r, "PUT")
529 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
530 th.TestJSONRequest(t, r, `{
531 "metadata": {
532 "foo": "bar",
533 "this": "that"
534 }
535 }`)
536
537 w.WriteHeader(http.StatusOK)
538 w.Header().Add("Content-Type", "application/json")
539 w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`))
540 })
541}
542
Jon Perritt78c57ce2014-11-20 11:07:18 -0700543// HandleMetadataUpdateSuccessfully sets up the test server to respond to a metadata Update request.
544func HandleMetadataUpdateSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700545 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
546 th.TestMethod(t, r, "POST")
547 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
548 th.TestJSONRequest(t, r, `{
549 "metadata": {
550 "foo": "baz",
551 "this": "those"
552 }
553 }`)
554
555 w.WriteHeader(http.StatusOK)
556 w.Header().Add("Content-Type", "application/json")
557 w.Write([]byte(`{ "metadata": {"foo":"baz", "this":"those"}}`))
558 })
559}