Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 1 | // +build fixtures |
Ash Wilson | 15e0f27 | 2014-10-21 15:33:02 -0400 | [diff] [blame] | 2 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 3 | package servers |
| 4 | |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 5 | import ( |
| 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 Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 14 | // ServerListBody contains the canned body of a servers.List response. |
| 15 | const 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. |
| 163 | const 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 | |
| 238 | var ( |
| 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 Topjian | 978bb50 | 2015-02-12 20:55:31 +0000 | [diff] [blame] | 288 | SecurityGroups: []map[string]interface{}{ |
| 289 | map[string]interface{}{ |
| 290 | "name": "default", |
| 291 | }, |
| 292 | }, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 293 | } |
| 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 Topjian | 978bb50 | 2015-02-12 20:55:31 +0000 | [diff] [blame] | 344 | SecurityGroups: []map[string]interface{}{ |
| 345 | map[string]interface{}{ |
| 346 | "name": "default", |
| 347 | }, |
| 348 | }, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 349 | } |
| 350 | ) |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 351 | |
| 352 | // HandleServerCreationSuccessfully sets up the test server to respond to a server creation request |
| 353 | // with a given response. |
| 354 | func 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 Wilson | a70510a | 2014-10-23 11:54:03 -0400 | [diff] [blame] | 372 | // HandleServerListSuccessfully sets up the test server to respond to a server List request. |
| 373 | func 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 Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 392 | // HandleServerDeletionSuccessfully sets up the test server to respond to a server deletion request. |
| 393 | func 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 Wilson | 1c1eb88 | 2014-10-21 18:14:31 -0400 | [diff] [blame] | 401 | |
Ian Duffy | 370c430 | 2016-01-21 10:44:56 +0000 | [diff] [blame] | 402 | // HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password |
| 403 | // change request. |
| 404 | func HandleServerForceDeletionSuccessfully(t *testing.T) { |
| 405 | th.Mux.HandleFunc("/servers/asdfasdfasdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 406 | th.TestMethod(t, r, "POST") |
| 407 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 408 | th.TestJSONRequest(t, r, `{ "forceDelete": "" }`) |
| 409 | |
| 410 | w.WriteHeader(http.StatusAccepted) |
| 411 | }) |
| 412 | } |
| 413 | |
Ash Wilson | 189c95c | 2014-10-23 11:41:35 -0400 | [diff] [blame] | 414 | // HandleServerGetSuccessfully sets up the test server to respond to a server Get request. |
| 415 | func HandleServerGetSuccessfully(t *testing.T) { |
| 416 | th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) { |
| 417 | th.TestMethod(t, r, "GET") |
| 418 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 419 | th.TestHeader(t, r, "Accept", "application/json") |
| 420 | |
| 421 | fmt.Fprintf(w, SingleServerBody) |
| 422 | }) |
| 423 | } |
| 424 | |
| 425 | // HandleServerUpdateSuccessfully sets up the test server to respond to a server Update request. |
| 426 | func HandleServerUpdateSuccessfully(t *testing.T) { |
| 427 | th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) { |
| 428 | th.TestMethod(t, r, "PUT") |
| 429 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 430 | th.TestHeader(t, r, "Accept", "application/json") |
| 431 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 432 | th.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`) |
| 433 | |
| 434 | fmt.Fprintf(w, SingleServerBody) |
| 435 | }) |
| 436 | } |
| 437 | |
Ash Wilson | 1c1eb88 | 2014-10-21 18:14:31 -0400 | [diff] [blame] | 438 | // HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password |
| 439 | // change request. |
| 440 | func HandleAdminPasswordChangeSuccessfully(t *testing.T) { |
| 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, `{ "changePassword": { "adminPass": "new-password" } }`) |
| 445 | |
| 446 | w.WriteHeader(http.StatusAccepted) |
| 447 | }) |
| 448 | } |
Ash Wilson | 2295ba5 | 2014-10-21 18:19:28 -0400 | [diff] [blame] | 449 | |
| 450 | // HandleRebootSuccessfully sets up the test server to respond to a reboot request with success. |
| 451 | func HandleRebootSuccessfully(t *testing.T) { |
| 452 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 453 | th.TestMethod(t, r, "POST") |
| 454 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 455 | th.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`) |
| 456 | |
| 457 | w.WriteHeader(http.StatusAccepted) |
| 458 | }) |
| 459 | } |
Ash Wilson | acf49c6 | 2014-10-21 18:25:11 -0400 | [diff] [blame] | 460 | |
| 461 | // HandleRebuildSuccessfully sets up the test server to respond to a rebuild request with success. |
| 462 | func HandleRebuildSuccessfully(t *testing.T, response string) { |
| 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, ` |
| 467 | { |
| 468 | "rebuild": { |
| 469 | "name": "new-name", |
| 470 | "adminPass": "swordfish", |
| 471 | "imageRef": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 472 | "accessIPv4": "1.2.3.4" |
| 473 | } |
| 474 | } |
| 475 | `) |
| 476 | |
| 477 | w.WriteHeader(http.StatusAccepted) |
| 478 | w.Header().Add("Content-Type", "application/json") |
| 479 | fmt.Fprintf(w, response) |
| 480 | }) |
| 481 | } |
Alex Gaynor | fa8fbeb | 2014-11-13 13:39:31 -0800 | [diff] [blame] | 482 | |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 483 | // HandleServerRescueSuccessfully sets up the test server to respond to a server Rescue request. |
Alex Gaynor | fa8fbeb | 2014-11-13 13:39:31 -0800 | [diff] [blame] | 484 | func HandleServerRescueSuccessfully(t *testing.T) { |
| 485 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 486 | th.TestMethod(t, r, "POST") |
| 487 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 488 | th.TestJSONRequest(t, r, `{ "rescue": { "adminPass": "1234567890" } }`) |
| 489 | |
| 490 | w.WriteHeader(http.StatusOK) |
| 491 | w.Write([]byte(`{ "adminPass": "1234567890" }`)) |
| 492 | }) |
| 493 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 494 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 495 | // HandleMetadatumGetSuccessfully sets up the test server to respond to a metadatum Get request. |
| 496 | func HandleMetadatumGetSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 497 | th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) { |
| 498 | th.TestMethod(t, r, "GET") |
| 499 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 500 | th.TestHeader(t, r, "Accept", "application/json") |
| 501 | |
| 502 | w.WriteHeader(http.StatusOK) |
| 503 | w.Header().Add("Content-Type", "application/json") |
| 504 | w.Write([]byte(`{ "meta": {"foo":"bar"}}`)) |
| 505 | }) |
| 506 | } |
| 507 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 508 | // HandleMetadatumCreateSuccessfully sets up the test server to respond to a metadatum Create request. |
| 509 | func HandleMetadatumCreateSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 510 | th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) { |
| 511 | th.TestMethod(t, r, "PUT") |
| 512 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 513 | th.TestJSONRequest(t, r, `{ |
| 514 | "meta": { |
| 515 | "foo": "bar" |
| 516 | } |
| 517 | }`) |
| 518 | |
| 519 | w.WriteHeader(http.StatusOK) |
| 520 | w.Header().Add("Content-Type", "application/json") |
| 521 | w.Write([]byte(`{ "meta": {"foo":"bar"}}`)) |
| 522 | }) |
| 523 | } |
| 524 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 525 | // HandleMetadatumDeleteSuccessfully sets up the test server to respond to a metadatum Delete request. |
| 526 | func HandleMetadatumDeleteSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 527 | th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) { |
| 528 | th.TestMethod(t, r, "DELETE") |
| 529 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 530 | |
| 531 | w.WriteHeader(http.StatusNoContent) |
| 532 | }) |
| 533 | } |
| 534 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 535 | // HandleMetadataGetSuccessfully sets up the test server to respond to a metadata Get request. |
| 536 | func HandleMetadataGetSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 537 | th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 538 | th.TestMethod(t, r, "GET") |
| 539 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 540 | th.TestHeader(t, r, "Accept", "application/json") |
| 541 | |
| 542 | w.WriteHeader(http.StatusOK) |
| 543 | w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`)) |
| 544 | }) |
| 545 | } |
| 546 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 547 | // HandleMetadataResetSuccessfully sets up the test server to respond to a metadata Create request. |
| 548 | func HandleMetadataResetSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 549 | th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 550 | th.TestMethod(t, r, "PUT") |
| 551 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 552 | th.TestJSONRequest(t, r, `{ |
| 553 | "metadata": { |
| 554 | "foo": "bar", |
| 555 | "this": "that" |
| 556 | } |
| 557 | }`) |
| 558 | |
| 559 | w.WriteHeader(http.StatusOK) |
| 560 | w.Header().Add("Content-Type", "application/json") |
| 561 | w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`)) |
| 562 | }) |
| 563 | } |
| 564 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 565 | // HandleMetadataUpdateSuccessfully sets up the test server to respond to a metadata Update request. |
| 566 | func HandleMetadataUpdateSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 567 | th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 568 | th.TestMethod(t, r, "POST") |
| 569 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 570 | th.TestJSONRequest(t, r, `{ |
| 571 | "metadata": { |
| 572 | "foo": "baz", |
| 573 | "this": "those" |
| 574 | } |
| 575 | }`) |
| 576 | |
| 577 | w.WriteHeader(http.StatusOK) |
| 578 | w.Header().Add("Content-Type", "application/json") |
| 579 | w.Write([]byte(`{ "metadata": {"foo":"baz", "this":"those"}}`)) |
| 580 | }) |
| 581 | } |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 582 | |
| 583 | // ListAddressesExpected represents an expected repsonse from a ListAddresses request. |
| 584 | var ListAddressesExpected = map[string][]Address{ |
| 585 | "public": []Address{ |
| 586 | Address{ |
| 587 | Version: 4, |
| 588 | Address: "80.56.136.39", |
| 589 | }, |
| 590 | Address{ |
| 591 | Version: 6, |
| 592 | Address: "2001:4800:790e:510:be76:4eff:fe04:82a8", |
| 593 | }, |
| 594 | }, |
| 595 | "private": []Address{ |
| 596 | Address{ |
| 597 | Version: 4, |
| 598 | Address: "10.880.3.154", |
| 599 | }, |
| 600 | }, |
| 601 | } |
| 602 | |
| 603 | // HandleAddressListSuccessfully sets up the test server to respond to a ListAddresses request. |
| 604 | func HandleAddressListSuccessfully(t *testing.T) { |
| 605 | th.Mux.HandleFunc("/servers/asdfasdfasdf/ips", func(w http.ResponseWriter, r *http.Request) { |
| 606 | th.TestMethod(t, r, "GET") |
| 607 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 608 | |
| 609 | w.Header().Add("Content-Type", "application/json") |
| 610 | fmt.Fprintf(w, `{ |
| 611 | "addresses": { |
| 612 | "public": [ |
| 613 | { |
| 614 | "version": 4, |
| 615 | "addr": "50.56.176.35" |
| 616 | }, |
| 617 | { |
| 618 | "version": 6, |
| 619 | "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8" |
| 620 | } |
| 621 | ], |
| 622 | "private": [ |
| 623 | { |
| 624 | "version": 4, |
| 625 | "addr": "10.180.3.155" |
| 626 | } |
| 627 | ] |
| 628 | } |
| 629 | }`) |
| 630 | }) |
| 631 | } |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 632 | |
| 633 | // ListNetworkAddressesExpected represents an expected repsonse from a ListAddressesByNetwork request. |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 634 | var ListNetworkAddressesExpected = []Address{ |
| 635 | Address{ |
| 636 | Version: 4, |
| 637 | Address: "50.56.176.35", |
| 638 | }, |
| 639 | Address{ |
| 640 | Version: 6, |
| 641 | Address: "2001:4800:780e:510:be76:4eff:fe04:84a8", |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 642 | }, |
| 643 | } |
| 644 | |
| 645 | // HandleNetworkAddressListSuccessfully sets up the test server to respond to a ListAddressesByNetwork request. |
| 646 | func HandleNetworkAddressListSuccessfully(t *testing.T) { |
| 647 | th.Mux.HandleFunc("/servers/asdfasdfasdf/ips/public", func(w http.ResponseWriter, r *http.Request) { |
| 648 | th.TestMethod(t, r, "GET") |
| 649 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 650 | |
| 651 | w.Header().Add("Content-Type", "application/json") |
| 652 | fmt.Fprintf(w, `{ |
| 653 | "public": [ |
| 654 | { |
| 655 | "version": 4, |
| 656 | "addr": "50.56.176.35" |
| 657 | }, |
| 658 | { |
| 659 | "version": 6, |
| 660 | "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8" |
| 661 | } |
| 662 | ] |
| 663 | }`) |
| 664 | }) |
| 665 | } |
einarf | 2fc665e | 2015-04-16 20:16:21 +0000 | [diff] [blame] | 666 | |
| 667 | // HandleCreateServerImageSuccessfully sets up the test server to respond to a TestCreateServerImage request. |
| 668 | func HandleCreateServerImageSuccessfully(t *testing.T) { |
| 669 | th.Mux.HandleFunc("/servers/serverimage/action", func(w http.ResponseWriter, r *http.Request) { |
| 670 | th.TestMethod(t, r, "POST") |
| 671 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 672 | w.Header().Add("Location", "https://0.0.0.0/images/xxxx-xxxxx-xxxxx-xxxx") |
| 673 | w.WriteHeader(http.StatusAccepted) |
| 674 | }) |
| 675 | } |
| 676 | |