blob: 85cea70a88314ddc8bde9731048143152cc7bb3c [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
Rickard von Essen5b8bbff2016-02-16 07:48:20 +0100238const ServerPasswordBody = `
239{
240 "password": "xlozO3wLCBRWAa2yDjCCVx8vwNPypxnypmRYDa/zErlQ+EzPe1S/Gz6nfmC52mOlOSCRuUOmG7kqqgejPof6M7bOezS387zjq4LSvvwp28zUknzy4YzfFGhnHAdai3TxUJ26pfQCYrq8UTzmKF2Bq8ioSEtVVzM0A96pDh8W2i7BOz6MdoiVyiev/I1K2LsuipfxSJR7Wdke4zNXJjHHP2RfYsVbZ/k9ANu+Nz4iIH8/7Cacud/pphH7EjrY6a4RZNrjQskrhKYed0YERpotyjYk1eDtRe72GrSiXteqCM4biaQ5w3ruS+AcX//PXk3uJ5kC7d67fPXaVz4WaQRYMg=="
241}
242`
243
Ash Wilsone77ffb02014-10-20 13:10:26 -0400244var (
245 // ServerHerp is a Server struct that should correspond to the first result in ServerListBody.
246 ServerHerp = Server{
247 Status: "ACTIVE",
248 Updated: "2014-09-25T13:10:10Z",
249 HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
250 Addresses: map[string]interface{}{
251 "private": []interface{}{
252 map[string]interface{}{
253 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
254 "version": float64(4),
255 "addr": "10.0.0.32",
256 "OS-EXT-IPS:type": "fixed",
257 },
258 },
259 },
260 Links: []interface{}{
261 map[string]interface{}{
262 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
263 "rel": "self",
264 },
265 map[string]interface{}{
266 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
267 "rel": "bookmark",
268 },
269 },
270 Image: map[string]interface{}{
271 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
272 "links": []interface{}{
273 map[string]interface{}{
274 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
275 "rel": "bookmark",
276 },
277 },
278 },
279 Flavor: map[string]interface{}{
280 "id": "1",
281 "links": []interface{}{
282 map[string]interface{}{
283 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
284 "rel": "bookmark",
285 },
286 },
287 },
288 ID: "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
289 UserID: "9349aff8be7545ac9d2f1d00999a23cd",
290 Name: "herp",
291 Created: "2014-09-25T13:10:02Z",
292 TenantID: "fcad67a6189847c4aecfa3c81a05783b",
293 Metadata: map[string]interface{}{},
Joe Topjian978bb502015-02-12 20:55:31 +0000294 SecurityGroups: []map[string]interface{}{
295 map[string]interface{}{
296 "name": "default",
297 },
298 },
Ash Wilsone77ffb02014-10-20 13:10:26 -0400299 }
300
301 // ServerDerp is a Server struct that should correspond to the second server in ServerListBody.
302 ServerDerp = Server{
303 Status: "ACTIVE",
304 Updated: "2014-09-25T13:04:49Z",
305 HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
306 Addresses: map[string]interface{}{
307 "private": []interface{}{
308 map[string]interface{}{
309 "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
310 "version": float64(4),
311 "addr": "10.0.0.31",
312 "OS-EXT-IPS:type": "fixed",
313 },
314 },
315 },
316 Links: []interface{}{
317 map[string]interface{}{
318 "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
319 "rel": "self",
320 },
321 map[string]interface{}{
322 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
323 "rel": "bookmark",
324 },
325 },
326 Image: map[string]interface{}{
327 "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
328 "links": []interface{}{
329 map[string]interface{}{
330 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
331 "rel": "bookmark",
332 },
333 },
334 },
335 Flavor: map[string]interface{}{
336 "id": "1",
337 "links": []interface{}{
338 map[string]interface{}{
339 "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
340 "rel": "bookmark",
341 },
342 },
343 },
344 ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
345 UserID: "9349aff8be7545ac9d2f1d00999a23cd",
346 Name: "derp",
347 Created: "2014-09-25T13:04:41Z",
348 TenantID: "fcad67a6189847c4aecfa3c81a05783b",
349 Metadata: map[string]interface{}{},
Joe Topjian978bb502015-02-12 20:55:31 +0000350 SecurityGroups: []map[string]interface{}{
351 map[string]interface{}{
352 "name": "default",
353 },
354 },
Ash Wilsone77ffb02014-10-20 13:10:26 -0400355 }
356)
Ash Wilson664fe332014-10-21 17:47:49 -0400357
358// HandleServerCreationSuccessfully sets up the test server to respond to a server creation request
359// with a given response.
360func HandleServerCreationSuccessfully(t *testing.T, response string) {
361 th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
362 th.TestMethod(t, r, "POST")
363 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
364 th.TestJSONRequest(t, r, `{
365 "server": {
366 "name": "derp",
367 "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb",
368 "flavorRef": "1"
369 }
370 }`)
371
372 w.WriteHeader(http.StatusAccepted)
373 w.Header().Add("Content-Type", "application/json")
374 fmt.Fprintf(w, response)
375 })
376}
377
Ash Wilsona70510a2014-10-23 11:54:03 -0400378// HandleServerListSuccessfully sets up the test server to respond to a server List request.
379func HandleServerListSuccessfully(t *testing.T) {
380 th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
381 th.TestMethod(t, r, "GET")
382 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
383
384 w.Header().Add("Content-Type", "application/json")
385 r.ParseForm()
386 marker := r.Form.Get("marker")
387 switch marker {
388 case "":
389 fmt.Fprintf(w, ServerListBody)
390 case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
391 fmt.Fprintf(w, `{ "servers": [] }`)
392 default:
393 t.Fatalf("/servers/detail invoked with unexpected marker=[%s]", marker)
394 }
395 })
396}
397
Ash Wilson664fe332014-10-21 17:47:49 -0400398// HandleServerDeletionSuccessfully sets up the test server to respond to a server deletion request.
399func HandleServerDeletionSuccessfully(t *testing.T) {
400 th.Mux.HandleFunc("/servers/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
401 th.TestMethod(t, r, "DELETE")
402 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
403
404 w.WriteHeader(http.StatusNoContent)
405 })
406}
Ash Wilson1c1eb882014-10-21 18:14:31 -0400407
Rickard von Essen5b8bbff2016-02-16 07:48:20 +0100408// HandleServerForceDeletionSuccessfully sets up the test server to respond to a server force deletion
409// request.
Ian Duffy370c4302016-01-21 10:44:56 +0000410func HandleServerForceDeletionSuccessfully(t *testing.T) {
411 th.Mux.HandleFunc("/servers/asdfasdfasdf/action", func(w http.ResponseWriter, r *http.Request) {
412 th.TestMethod(t, r, "POST")
413 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
414 th.TestJSONRequest(t, r, `{ "forceDelete": "" }`)
415
416 w.WriteHeader(http.StatusAccepted)
417 })
418}
419
Ash Wilson189c95c2014-10-23 11:41:35 -0400420// HandleServerGetSuccessfully sets up the test server to respond to a server Get request.
421func HandleServerGetSuccessfully(t *testing.T) {
422 th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
423 th.TestMethod(t, r, "GET")
424 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
425 th.TestHeader(t, r, "Accept", "application/json")
426
427 fmt.Fprintf(w, SingleServerBody)
428 })
429}
430
431// HandleServerUpdateSuccessfully sets up the test server to respond to a server Update request.
432func HandleServerUpdateSuccessfully(t *testing.T) {
433 th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
434 th.TestMethod(t, r, "PUT")
435 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
436 th.TestHeader(t, r, "Accept", "application/json")
437 th.TestHeader(t, r, "Content-Type", "application/json")
438 th.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`)
439
440 fmt.Fprintf(w, SingleServerBody)
441 })
442}
443
Ash Wilson1c1eb882014-10-21 18:14:31 -0400444// HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password
445// change request.
446func HandleAdminPasswordChangeSuccessfully(t *testing.T) {
447 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
448 th.TestMethod(t, r, "POST")
449 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
450 th.TestJSONRequest(t, r, `{ "changePassword": { "adminPass": "new-password" } }`)
451
452 w.WriteHeader(http.StatusAccepted)
453 })
454}
Ash Wilson2295ba52014-10-21 18:19:28 -0400455
456// HandleRebootSuccessfully sets up the test server to respond to a reboot request with success.
457func HandleRebootSuccessfully(t *testing.T) {
458 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
459 th.TestMethod(t, r, "POST")
460 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
461 th.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`)
462
463 w.WriteHeader(http.StatusAccepted)
464 })
465}
Ash Wilsonacf49c62014-10-21 18:25:11 -0400466
467// HandleRebuildSuccessfully sets up the test server to respond to a rebuild request with success.
468func HandleRebuildSuccessfully(t *testing.T, response string) {
469 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
470 th.TestMethod(t, r, "POST")
471 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
472 th.TestJSONRequest(t, r, `
473 {
474 "rebuild": {
475 "name": "new-name",
476 "adminPass": "swordfish",
477 "imageRef": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
478 "accessIPv4": "1.2.3.4"
479 }
480 }
481 `)
482
483 w.WriteHeader(http.StatusAccepted)
484 w.Header().Add("Content-Type", "application/json")
485 fmt.Fprintf(w, response)
486 })
487}
Alex Gaynorfa8fbeb2014-11-13 13:39:31 -0800488
Jon Perrittcc77da62014-11-16 13:14:21 -0700489// HandleServerRescueSuccessfully sets up the test server to respond to a server Rescue request.
Alex Gaynorfa8fbeb2014-11-13 13:39:31 -0800490func HandleServerRescueSuccessfully(t *testing.T) {
491 th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
492 th.TestMethod(t, r, "POST")
493 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
494 th.TestJSONRequest(t, r, `{ "rescue": { "adminPass": "1234567890" } }`)
495
496 w.WriteHeader(http.StatusOK)
497 w.Write([]byte(`{ "adminPass": "1234567890" }`))
498 })
499}
Jon Perrittcc77da62014-11-16 13:14:21 -0700500
Jon Perritt78c57ce2014-11-20 11:07:18 -0700501// HandleMetadatumGetSuccessfully sets up the test server to respond to a metadatum Get request.
502func HandleMetadatumGetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700503 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
504 th.TestMethod(t, r, "GET")
505 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
506 th.TestHeader(t, r, "Accept", "application/json")
507
508 w.WriteHeader(http.StatusOK)
509 w.Header().Add("Content-Type", "application/json")
510 w.Write([]byte(`{ "meta": {"foo":"bar"}}`))
511 })
512}
513
Jon Perritt78c57ce2014-11-20 11:07:18 -0700514// HandleMetadatumCreateSuccessfully sets up the test server to respond to a metadatum Create request.
515func HandleMetadatumCreateSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700516 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
517 th.TestMethod(t, r, "PUT")
518 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
519 th.TestJSONRequest(t, r, `{
520 "meta": {
521 "foo": "bar"
522 }
523 }`)
524
525 w.WriteHeader(http.StatusOK)
526 w.Header().Add("Content-Type", "application/json")
527 w.Write([]byte(`{ "meta": {"foo":"bar"}}`))
528 })
529}
530
Jon Perritt78c57ce2014-11-20 11:07:18 -0700531// HandleMetadatumDeleteSuccessfully sets up the test server to respond to a metadatum Delete request.
532func HandleMetadatumDeleteSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700533 th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) {
534 th.TestMethod(t, r, "DELETE")
535 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
536
537 w.WriteHeader(http.StatusNoContent)
538 })
539}
540
Jon Perritt78c57ce2014-11-20 11:07:18 -0700541// HandleMetadataGetSuccessfully sets up the test server to respond to a metadata Get request.
542func HandleMetadataGetSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700543 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
544 th.TestMethod(t, r, "GET")
545 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
546 th.TestHeader(t, r, "Accept", "application/json")
547
548 w.WriteHeader(http.StatusOK)
549 w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`))
550 })
551}
552
Jon Perritt789f8322014-11-21 08:20:04 -0700553// HandleMetadataResetSuccessfully sets up the test server to respond to a metadata Create request.
554func HandleMetadataResetSuccessfully(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, "PUT")
557 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
558 th.TestJSONRequest(t, r, `{
559 "metadata": {
560 "foo": "bar",
561 "this": "that"
562 }
563 }`)
564
565 w.WriteHeader(http.StatusOK)
566 w.Header().Add("Content-Type", "application/json")
567 w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`))
568 })
569}
570
Jon Perritt78c57ce2014-11-20 11:07:18 -0700571// HandleMetadataUpdateSuccessfully sets up the test server to respond to a metadata Update request.
572func HandleMetadataUpdateSuccessfully(t *testing.T) {
Jon Perrittcc77da62014-11-16 13:14:21 -0700573 th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) {
574 th.TestMethod(t, r, "POST")
575 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
576 th.TestJSONRequest(t, r, `{
577 "metadata": {
578 "foo": "baz",
579 "this": "those"
580 }
581 }`)
582
583 w.WriteHeader(http.StatusOK)
584 w.Header().Add("Content-Type", "application/json")
585 w.Write([]byte(`{ "metadata": {"foo":"baz", "this":"those"}}`))
586 })
587}
Jon Perritt5cb49482015-02-19 12:19:58 -0700588
589// ListAddressesExpected represents an expected repsonse from a ListAddresses request.
590var ListAddressesExpected = map[string][]Address{
591 "public": []Address{
592 Address{
593 Version: 4,
594 Address: "80.56.136.39",
595 },
596 Address{
597 Version: 6,
598 Address: "2001:4800:790e:510:be76:4eff:fe04:82a8",
599 },
600 },
601 "private": []Address{
602 Address{
603 Version: 4,
604 Address: "10.880.3.154",
605 },
606 },
607}
608
609// HandleAddressListSuccessfully sets up the test server to respond to a ListAddresses request.
610func HandleAddressListSuccessfully(t *testing.T) {
611 th.Mux.HandleFunc("/servers/asdfasdfasdf/ips", func(w http.ResponseWriter, r *http.Request) {
612 th.TestMethod(t, r, "GET")
613 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
614
615 w.Header().Add("Content-Type", "application/json")
616 fmt.Fprintf(w, `{
617 "addresses": {
618 "public": [
619 {
620 "version": 4,
621 "addr": "50.56.176.35"
622 },
623 {
624 "version": 6,
625 "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8"
626 }
627 ],
628 "private": [
629 {
630 "version": 4,
631 "addr": "10.180.3.155"
632 }
633 ]
634 }
635 }`)
636 })
637}
Jon Perritt04d073c2015-02-19 21:46:23 -0700638
639// ListNetworkAddressesExpected represents an expected repsonse from a ListAddressesByNetwork request.
Jon Perrittb51ba9c2015-02-23 10:56:35 -0700640var ListNetworkAddressesExpected = []Address{
641 Address{
642 Version: 4,
643 Address: "50.56.176.35",
644 },
645 Address{
646 Version: 6,
647 Address: "2001:4800:780e:510:be76:4eff:fe04:84a8",
Jon Perritt04d073c2015-02-19 21:46:23 -0700648 },
649}
650
651// HandleNetworkAddressListSuccessfully sets up the test server to respond to a ListAddressesByNetwork request.
652func HandleNetworkAddressListSuccessfully(t *testing.T) {
653 th.Mux.HandleFunc("/servers/asdfasdfasdf/ips/public", func(w http.ResponseWriter, r *http.Request) {
654 th.TestMethod(t, r, "GET")
655 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
656
657 w.Header().Add("Content-Type", "application/json")
658 fmt.Fprintf(w, `{
659 "public": [
660 {
661 "version": 4,
662 "addr": "50.56.176.35"
663 },
664 {
665 "version": 6,
666 "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8"
667 }
668 ]
669 }`)
670 })
671}
einarf2fc665e2015-04-16 20:16:21 +0000672
673// HandleCreateServerImageSuccessfully sets up the test server to respond to a TestCreateServerImage request.
674func HandleCreateServerImageSuccessfully(t *testing.T) {
675 th.Mux.HandleFunc("/servers/serverimage/action", func(w http.ResponseWriter, r *http.Request) {
676 th.TestMethod(t, r, "POST")
677 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
678 w.Header().Add("Location", "https://0.0.0.0/images/xxxx-xxxxx-xxxxx-xxxx")
679 w.WriteHeader(http.StatusAccepted)
680 })
681}
682
Rickard von Essen5b8bbff2016-02-16 07:48:20 +0100683// HandlePasswordGetSuccessfully sets up the test server to respond to a password Get request.
684func HandlePasswordGetSuccessfully(t *testing.T) {
685 th.Mux.HandleFunc("/servers/1234asdf/os-server-password", func(w http.ResponseWriter, r *http.Request) {
686 th.TestMethod(t, r, "GET")
687 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
688 th.TestHeader(t, r, "Accept", "application/json")
689
690 fmt.Fprintf(w, ServerPasswordBody)
691 })
692}