jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 2 | |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 7 | "time" |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 8 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame^] | 9 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 10 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/compute/v2/servers" |
| 11 | th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper" |
| 12 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client" |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 13 | ) |
| 14 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 15 | // ServerListBody contains the canned body of a servers.List response. |
| 16 | const ServerListBody = ` |
| 17 | { |
| 18 | "servers": [ |
| 19 | { |
| 20 | "status": "ACTIVE", |
| 21 | "updated": "2014-09-25T13:10:10Z", |
| 22 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 23 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 24 | "addresses": { |
| 25 | "private": [ |
| 26 | { |
| 27 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b", |
| 28 | "version": 4, |
| 29 | "addr": "10.0.0.32", |
| 30 | "OS-EXT-IPS:type": "fixed" |
| 31 | } |
| 32 | ] |
| 33 | }, |
| 34 | "links": [ |
| 35 | { |
| 36 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 37 | "rel": "self" |
| 38 | }, |
| 39 | { |
| 40 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 41 | "rel": "bookmark" |
| 42 | } |
| 43 | ], |
| 44 | "key_name": null, |
| 45 | "image": { |
| 46 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 47 | "links": [ |
| 48 | { |
| 49 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 50 | "rel": "bookmark" |
| 51 | } |
| 52 | ] |
| 53 | }, |
| 54 | "OS-EXT-STS:task_state": null, |
| 55 | "OS-EXT-STS:vm_state": "active", |
| 56 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001e", |
| 57 | "OS-SRV-USG:launched_at": "2014-09-25T13:10:10.000000", |
| 58 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 59 | "flavor": { |
| 60 | "id": "1", |
| 61 | "links": [ |
| 62 | { |
| 63 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 64 | "rel": "bookmark" |
| 65 | } |
| 66 | ] |
| 67 | }, |
| 68 | "id": "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 69 | "security_groups": [ |
| 70 | { |
| 71 | "name": "default" |
| 72 | } |
| 73 | ], |
| 74 | "OS-SRV-USG:terminated_at": null, |
| 75 | "OS-EXT-AZ:availability_zone": "nova", |
| 76 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 77 | "name": "herp", |
| 78 | "created": "2014-09-25T13:10:02Z", |
| 79 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 80 | "OS-DCF:diskConfig": "MANUAL", |
| 81 | "os-extended-volumes:volumes_attached": [], |
| 82 | "accessIPv4": "", |
| 83 | "accessIPv6": "", |
| 84 | "progress": 0, |
| 85 | "OS-EXT-STS:power_state": 1, |
| 86 | "config_drive": "", |
| 87 | "metadata": {} |
| 88 | }, |
| 89 | { |
| 90 | "status": "ACTIVE", |
| 91 | "updated": "2014-09-25T13:04:49Z", |
| 92 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 93 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 94 | "addresses": { |
| 95 | "private": [ |
| 96 | { |
| 97 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 98 | "version": 4, |
| 99 | "addr": "10.0.0.31", |
| 100 | "OS-EXT-IPS:type": "fixed" |
| 101 | } |
| 102 | ] |
| 103 | }, |
| 104 | "links": [ |
| 105 | { |
| 106 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 107 | "rel": "self" |
| 108 | }, |
| 109 | { |
| 110 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 111 | "rel": "bookmark" |
| 112 | } |
| 113 | ], |
| 114 | "key_name": null, |
| 115 | "image": { |
| 116 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 117 | "links": [ |
| 118 | { |
| 119 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 120 | "rel": "bookmark" |
| 121 | } |
| 122 | ] |
| 123 | }, |
| 124 | "OS-EXT-STS:task_state": null, |
| 125 | "OS-EXT-STS:vm_state": "active", |
| 126 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d", |
| 127 | "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000", |
| 128 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 129 | "flavor": { |
| 130 | "id": "1", |
| 131 | "links": [ |
| 132 | { |
| 133 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 134 | "rel": "bookmark" |
| 135 | } |
| 136 | ] |
| 137 | }, |
| 138 | "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 139 | "security_groups": [ |
| 140 | { |
| 141 | "name": "default" |
| 142 | } |
| 143 | ], |
| 144 | "OS-SRV-USG:terminated_at": null, |
| 145 | "OS-EXT-AZ:availability_zone": "nova", |
| 146 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 147 | "name": "derp", |
| 148 | "created": "2014-09-25T13:04:41Z", |
| 149 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 150 | "OS-DCF:diskConfig": "MANUAL", |
| 151 | "os-extended-volumes:volumes_attached": [], |
| 152 | "accessIPv4": "", |
| 153 | "accessIPv6": "", |
| 154 | "progress": 0, |
| 155 | "OS-EXT-STS:power_state": 1, |
| 156 | "config_drive": "", |
| 157 | "metadata": {} |
jrperritt | 1fa9250 | 2016-07-21 19:22:59 -0500 | [diff] [blame] | 158 | }, |
| 159 | { |
| 160 | "status": "ACTIVE", |
| 161 | "updated": "2014-09-25T13:04:49Z", |
| 162 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 163 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 164 | "addresses": { |
| 165 | "private": [ |
| 166 | { |
| 167 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 168 | "version": 4, |
| 169 | "addr": "10.0.0.31", |
| 170 | "OS-EXT-IPS:type": "fixed" |
| 171 | } |
| 172 | ] |
| 173 | }, |
| 174 | "links": [ |
| 175 | { |
| 176 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 177 | "rel": "self" |
| 178 | }, |
| 179 | { |
| 180 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 181 | "rel": "bookmark" |
| 182 | } |
| 183 | ], |
| 184 | "key_name": null, |
| 185 | "image": "", |
| 186 | "OS-EXT-STS:task_state": null, |
| 187 | "OS-EXT-STS:vm_state": "active", |
| 188 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d", |
| 189 | "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000", |
| 190 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 191 | "flavor": { |
| 192 | "id": "1", |
| 193 | "links": [ |
| 194 | { |
| 195 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 196 | "rel": "bookmark" |
| 197 | } |
| 198 | ] |
| 199 | }, |
| 200 | "id": "9e5476bd-a4ec-4653-93d6-72c93aa682bb", |
| 201 | "security_groups": [ |
| 202 | { |
| 203 | "name": "default" |
| 204 | } |
| 205 | ], |
| 206 | "OS-SRV-USG:terminated_at": null, |
| 207 | "OS-EXT-AZ:availability_zone": "nova", |
| 208 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 209 | "name": "merp", |
| 210 | "created": "2014-09-25T13:04:41Z", |
| 211 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 212 | "OS-DCF:diskConfig": "MANUAL", |
| 213 | "os-extended-volumes:volumes_attached": [], |
| 214 | "accessIPv4": "", |
| 215 | "accessIPv6": "", |
| 216 | "progress": 0, |
| 217 | "OS-EXT-STS:power_state": 1, |
| 218 | "config_drive": "", |
| 219 | "metadata": {} |
| 220 | } |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 221 | ] |
| 222 | } |
| 223 | ` |
| 224 | |
| 225 | // SingleServerBody is the canned body of a Get request on an existing server. |
| 226 | const SingleServerBody = ` |
| 227 | { |
| 228 | "server": { |
| 229 | "status": "ACTIVE", |
| 230 | "updated": "2014-09-25T13:04:49Z", |
| 231 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 232 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 233 | "addresses": { |
| 234 | "private": [ |
| 235 | { |
| 236 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 237 | "version": 4, |
| 238 | "addr": "10.0.0.31", |
| 239 | "OS-EXT-IPS:type": "fixed" |
| 240 | } |
| 241 | ] |
| 242 | }, |
| 243 | "links": [ |
| 244 | { |
| 245 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 246 | "rel": "self" |
| 247 | }, |
| 248 | { |
| 249 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 250 | "rel": "bookmark" |
| 251 | } |
| 252 | ], |
| 253 | "key_name": null, |
| 254 | "image": { |
| 255 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 256 | "links": [ |
| 257 | { |
| 258 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 259 | "rel": "bookmark" |
| 260 | } |
| 261 | ] |
| 262 | }, |
| 263 | "OS-EXT-STS:task_state": null, |
| 264 | "OS-EXT-STS:vm_state": "active", |
| 265 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d", |
| 266 | "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000", |
| 267 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 268 | "flavor": { |
| 269 | "id": "1", |
| 270 | "links": [ |
| 271 | { |
| 272 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 273 | "rel": "bookmark" |
| 274 | } |
| 275 | ] |
| 276 | }, |
| 277 | "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 278 | "security_groups": [ |
| 279 | { |
| 280 | "name": "default" |
| 281 | } |
| 282 | ], |
| 283 | "OS-SRV-USG:terminated_at": null, |
| 284 | "OS-EXT-AZ:availability_zone": "nova", |
| 285 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 286 | "name": "derp", |
| 287 | "created": "2014-09-25T13:04:41Z", |
| 288 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 289 | "OS-DCF:diskConfig": "MANUAL", |
| 290 | "os-extended-volumes:volumes_attached": [], |
| 291 | "accessIPv4": "", |
| 292 | "accessIPv6": "", |
| 293 | "progress": 0, |
| 294 | "OS-EXT-STS:power_state": 1, |
| 295 | "config_drive": "", |
| 296 | "metadata": {} |
| 297 | } |
| 298 | } |
| 299 | ` |
| 300 | |
Rickard von Essen | 5b8bbff | 2016-02-16 07:48:20 +0100 | [diff] [blame] | 301 | const ServerPasswordBody = ` |
| 302 | { |
| 303 | "password": "xlozO3wLCBRWAa2yDjCCVx8vwNPypxnypmRYDa/zErlQ+EzPe1S/Gz6nfmC52mOlOSCRuUOmG7kqqgejPof6M7bOezS387zjq4LSvvwp28zUknzy4YzfFGhnHAdai3TxUJ26pfQCYrq8UTzmKF2Bq8ioSEtVVzM0A96pDh8W2i7BOz6MdoiVyiev/I1K2LsuipfxSJR7Wdke4zNXJjHHP2RfYsVbZ/k9ANu+Nz4iIH8/7Cacud/pphH7EjrY6a4RZNrjQskrhKYed0YERpotyjYk1eDtRe72GrSiXteqCM4biaQ5w3ruS+AcX//PXk3uJ5kC7d67fPXaVz4WaQRYMg==" |
| 304 | } |
| 305 | ` |
| 306 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 307 | var ( |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 308 | herpTimeCreated, _ = time.Parse(time.RFC3339, "2014-09-25T13:10:02Z") |
| 309 | herpTimeUpdated, _ = time.Parse(time.RFC3339, "2014-09-25T13:10:10Z") |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 310 | // ServerHerp is a Server struct that should correspond to the first result in ServerListBody. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 311 | ServerHerp = servers.Server{ |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 312 | Status: "ACTIVE", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 313 | Updated: herpTimeUpdated, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 314 | HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 315 | Addresses: map[string]interface{}{ |
| 316 | "private": []interface{}{ |
| 317 | map[string]interface{}{ |
| 318 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b", |
| 319 | "version": float64(4), |
| 320 | "addr": "10.0.0.32", |
| 321 | "OS-EXT-IPS:type": "fixed", |
| 322 | }, |
| 323 | }, |
| 324 | }, |
| 325 | Links: []interface{}{ |
| 326 | map[string]interface{}{ |
| 327 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 328 | "rel": "self", |
| 329 | }, |
| 330 | map[string]interface{}{ |
| 331 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 332 | "rel": "bookmark", |
| 333 | }, |
| 334 | }, |
| 335 | Image: map[string]interface{}{ |
| 336 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 337 | "links": []interface{}{ |
| 338 | map[string]interface{}{ |
| 339 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 340 | "rel": "bookmark", |
| 341 | }, |
| 342 | }, |
| 343 | }, |
| 344 | Flavor: map[string]interface{}{ |
| 345 | "id": "1", |
| 346 | "links": []interface{}{ |
| 347 | map[string]interface{}{ |
| 348 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 349 | "rel": "bookmark", |
| 350 | }, |
| 351 | }, |
| 352 | }, |
| 353 | ID: "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 354 | UserID: "9349aff8be7545ac9d2f1d00999a23cd", |
| 355 | Name: "herp", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 356 | Created: herpTimeCreated, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 357 | TenantID: "fcad67a6189847c4aecfa3c81a05783b", |
Joe Topjian | f464c96 | 2016-09-12 08:02:43 -0600 | [diff] [blame] | 358 | Metadata: map[string]string{}, |
Joe Topjian | 978bb50 | 2015-02-12 20:55:31 +0000 | [diff] [blame] | 359 | SecurityGroups: []map[string]interface{}{ |
| 360 | map[string]interface{}{ |
| 361 | "name": "default", |
| 362 | }, |
| 363 | }, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 364 | } |
| 365 | |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 366 | derpTimeCreated, _ = time.Parse(time.RFC3339, "2014-09-25T13:04:41Z") |
| 367 | derpTimeUpdated, _ = time.Parse(time.RFC3339, "2014-09-25T13:04:49Z") |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 368 | // ServerDerp is a Server struct that should correspond to the second server in ServerListBody. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 369 | ServerDerp = servers.Server{ |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 370 | Status: "ACTIVE", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 371 | Updated: derpTimeUpdated, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 372 | HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 373 | Addresses: map[string]interface{}{ |
| 374 | "private": []interface{}{ |
| 375 | map[string]interface{}{ |
| 376 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 377 | "version": float64(4), |
| 378 | "addr": "10.0.0.31", |
| 379 | "OS-EXT-IPS:type": "fixed", |
| 380 | }, |
| 381 | }, |
| 382 | }, |
| 383 | Links: []interface{}{ |
| 384 | map[string]interface{}{ |
| 385 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 386 | "rel": "self", |
| 387 | }, |
| 388 | map[string]interface{}{ |
| 389 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 390 | "rel": "bookmark", |
| 391 | }, |
| 392 | }, |
| 393 | Image: map[string]interface{}{ |
| 394 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 395 | "links": []interface{}{ |
| 396 | map[string]interface{}{ |
| 397 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 398 | "rel": "bookmark", |
| 399 | }, |
| 400 | }, |
| 401 | }, |
| 402 | Flavor: map[string]interface{}{ |
| 403 | "id": "1", |
| 404 | "links": []interface{}{ |
| 405 | map[string]interface{}{ |
| 406 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 407 | "rel": "bookmark", |
| 408 | }, |
| 409 | }, |
| 410 | }, |
| 411 | ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 412 | UserID: "9349aff8be7545ac9d2f1d00999a23cd", |
| 413 | Name: "derp", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 414 | Created: derpTimeCreated, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 415 | TenantID: "fcad67a6189847c4aecfa3c81a05783b", |
Joe Topjian | f464c96 | 2016-09-12 08:02:43 -0600 | [diff] [blame] | 416 | Metadata: map[string]string{}, |
Joe Topjian | 978bb50 | 2015-02-12 20:55:31 +0000 | [diff] [blame] | 417 | SecurityGroups: []map[string]interface{}{ |
| 418 | map[string]interface{}{ |
| 419 | "name": "default", |
| 420 | }, |
| 421 | }, |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 422 | } |
jrperritt | 1fa9250 | 2016-07-21 19:22:59 -0500 | [diff] [blame] | 423 | |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 424 | merpTimeCreated, _ = time.Parse(time.RFC3339, "2014-09-25T13:04:41Z") |
| 425 | merpTimeUpdated, _ = time.Parse(time.RFC3339, "2014-09-25T13:04:49Z") |
jrperritt | 1fa9250 | 2016-07-21 19:22:59 -0500 | [diff] [blame] | 426 | // ServerMerp is a Server struct that should correspond to the second server in ServerListBody. |
| 427 | ServerMerp = servers.Server{ |
| 428 | Status: "ACTIVE", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 429 | Updated: merpTimeUpdated, |
jrperritt | 1fa9250 | 2016-07-21 19:22:59 -0500 | [diff] [blame] | 430 | HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 431 | Addresses: map[string]interface{}{ |
| 432 | "private": []interface{}{ |
| 433 | map[string]interface{}{ |
| 434 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 435 | "version": float64(4), |
| 436 | "addr": "10.0.0.31", |
| 437 | "OS-EXT-IPS:type": "fixed", |
| 438 | }, |
| 439 | }, |
| 440 | }, |
| 441 | Links: []interface{}{ |
| 442 | map[string]interface{}{ |
| 443 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 444 | "rel": "self", |
| 445 | }, |
| 446 | map[string]interface{}{ |
| 447 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 448 | "rel": "bookmark", |
| 449 | }, |
| 450 | }, |
| 451 | Image: nil, |
| 452 | Flavor: map[string]interface{}{ |
| 453 | "id": "1", |
| 454 | "links": []interface{}{ |
| 455 | map[string]interface{}{ |
| 456 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 457 | "rel": "bookmark", |
| 458 | }, |
| 459 | }, |
| 460 | }, |
| 461 | ID: "9e5476bd-a4ec-4653-93d6-72c93aa682bb", |
| 462 | UserID: "9349aff8be7545ac9d2f1d00999a23cd", |
| 463 | Name: "merp", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 464 | Created: merpTimeCreated, |
jrperritt | 1fa9250 | 2016-07-21 19:22:59 -0500 | [diff] [blame] | 465 | TenantID: "fcad67a6189847c4aecfa3c81a05783b", |
Joe Topjian | f464c96 | 2016-09-12 08:02:43 -0600 | [diff] [blame] | 466 | Metadata: map[string]string{}, |
jrperritt | 1fa9250 | 2016-07-21 19:22:59 -0500 | [diff] [blame] | 467 | SecurityGroups: []map[string]interface{}{ |
| 468 | map[string]interface{}{ |
| 469 | "name": "default", |
| 470 | }, |
| 471 | }, |
| 472 | } |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 473 | ) |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 474 | |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 475 | type CreateOptsWithCustomField struct { |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 476 | servers.CreateOpts |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 477 | Foo string `json:"foo,omitempty"` |
| 478 | } |
| 479 | |
| 480 | func (opts CreateOptsWithCustomField) ToServerCreateMap() (map[string]interface{}, error) { |
| 481 | return gophercloud.BuildRequestBody(opts, "server") |
| 482 | } |
| 483 | |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 484 | // HandleServerCreationSuccessfully sets up the test server to respond to a server creation request |
| 485 | // with a given response. |
| 486 | func HandleServerCreationSuccessfully(t *testing.T, response string) { |
| 487 | th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) { |
| 488 | th.TestMethod(t, r, "POST") |
| 489 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 490 | th.TestJSONRequest(t, r, `{ |
| 491 | "server": { |
| 492 | "name": "derp", |
| 493 | "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 494 | "flavorRef": "1" |
| 495 | } |
| 496 | }`) |
| 497 | |
| 498 | w.WriteHeader(http.StatusAccepted) |
| 499 | w.Header().Add("Content-Type", "application/json") |
| 500 | fmt.Fprintf(w, response) |
| 501 | }) |
jrperritt | 0d7ed5d | 2016-08-16 11:23:26 -0500 | [diff] [blame] | 502 | |
| 503 | th.Mux.HandleFunc("/images/detail", func(w http.ResponseWriter, r *http.Request) { |
| 504 | th.TestMethod(t, r, "GET") |
| 505 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 506 | |
| 507 | w.Header().Add("Content-Type", "application/json") |
| 508 | r.ParseForm() |
| 509 | marker := r.Form.Get("marker") |
| 510 | switch marker { |
| 511 | case "": |
| 512 | fmt.Fprintf(w, ` |
| 513 | { |
| 514 | "images": [ |
| 515 | { |
| 516 | "status": "ACTIVE", |
| 517 | "updated": "2014-09-23T12:54:56Z", |
| 518 | "id": "f3e4a95d-1f4f-4989-97ce-f3a1fb8c04d7", |
| 519 | "OS-EXT-IMG-SIZE:size": 476704768, |
| 520 | "name": "F17-x86_64-cfntools", |
| 521 | "created": "2014-09-23T12:54:52Z", |
| 522 | "minDisk": 0, |
| 523 | "progress": 100, |
| 524 | "minRam": 0 |
| 525 | }, |
| 526 | { |
| 527 | "status": "ACTIVE", |
| 528 | "updated": "2014-09-23T12:51:43Z", |
| 529 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 530 | "OS-EXT-IMG-SIZE:size": 13167616, |
| 531 | "name": "cirros-0.3.2-x86_64-disk", |
| 532 | "created": "2014-09-23T12:51:42Z", |
| 533 | "minDisk": 0, |
| 534 | "progress": 100, |
| 535 | "minRam": 0 |
| 536 | } |
| 537 | ] |
| 538 | } |
| 539 | `) |
| 540 | case "2": |
| 541 | fmt.Fprintf(w, `{ "images": [] }`) |
| 542 | default: |
| 543 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 544 | } |
| 545 | }) |
| 546 | |
| 547 | th.Mux.HandleFunc("/flavors/detail", func(w http.ResponseWriter, r *http.Request) { |
| 548 | th.TestMethod(t, r, "GET") |
| 549 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 550 | |
| 551 | w.Header().Add("Content-Type", "application/json") |
| 552 | r.ParseForm() |
| 553 | marker := r.Form.Get("marker") |
| 554 | switch marker { |
| 555 | case "": |
| 556 | fmt.Fprintf(w, ` |
| 557 | { |
| 558 | "flavors": [ |
| 559 | { |
| 560 | "id": "1", |
| 561 | "name": "m1.tiny", |
| 562 | "disk": 1, |
| 563 | "ram": 512, |
| 564 | "vcpus": 1, |
| 565 | "swap":"" |
| 566 | }, |
| 567 | { |
| 568 | "id": "2", |
| 569 | "name": "m2.small", |
| 570 | "disk": 10, |
| 571 | "ram": 1024, |
| 572 | "vcpus": 2, |
| 573 | "swap": 1000 |
| 574 | } |
| 575 | ], |
| 576 | "flavors_links": [ |
| 577 | { |
| 578 | "href": "%s/flavors/detail?marker=2", |
| 579 | "rel": "next" |
| 580 | } |
| 581 | ] |
| 582 | } |
| 583 | `, th.Server.URL) |
| 584 | case "2": |
| 585 | fmt.Fprintf(w, `{ "flavors": [] }`) |
| 586 | default: |
| 587 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 588 | } |
| 589 | }) |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 592 | // HandleServerCreationWithCustomFieldSuccessfully sets up the test server to respond to a server creation request |
| 593 | // with a given response. |
| 594 | func HandleServerCreationWithCustomFieldSuccessfully(t *testing.T, response string) { |
| 595 | th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) { |
| 596 | th.TestMethod(t, r, "POST") |
| 597 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 598 | th.TestJSONRequest(t, r, `{ |
| 599 | "server": { |
| 600 | "name": "derp", |
| 601 | "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 602 | "flavorRef": "1", |
| 603 | "foo": "bar" |
| 604 | } |
| 605 | }`) |
| 606 | |
| 607 | w.WriteHeader(http.StatusAccepted) |
| 608 | w.Header().Add("Content-Type", "application/json") |
| 609 | fmt.Fprintf(w, response) |
| 610 | }) |
| 611 | } |
| 612 | |
Gavin Williams | cd65a06 | 2016-11-08 19:05:47 +0000 | [diff] [blame] | 613 | // HandleServerCreationWithUserdata sets up the test server to respond to a server creation request |
| 614 | // with a given response. |
| 615 | func HandleServerCreationWithUserdata(t *testing.T, response string) { |
| 616 | th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) { |
| 617 | th.TestMethod(t, r, "POST") |
| 618 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 619 | th.TestJSONRequest(t, r, `{ |
| 620 | "server": { |
| 621 | "name": "derp", |
| 622 | "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 623 | "flavorRef": "1", |
| 624 | "user_data": "dXNlcmRhdGEgc3RyaW5n" |
| 625 | } |
| 626 | }`) |
| 627 | |
| 628 | w.WriteHeader(http.StatusAccepted) |
| 629 | w.Header().Add("Content-Type", "application/json") |
| 630 | fmt.Fprintf(w, response) |
| 631 | }) |
| 632 | } |
| 633 | |
Joe Topjian | f464c96 | 2016-09-12 08:02:43 -0600 | [diff] [blame] | 634 | // HandleServerCreationWithMetadata sets up the test server to respond to a server creation request |
| 635 | // with a given response. |
| 636 | func HandleServerCreationWithMetadata(t *testing.T, response string) { |
| 637 | th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) { |
| 638 | th.TestMethod(t, r, "POST") |
| 639 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 640 | th.TestJSONRequest(t, r, `{ |
| 641 | "server": { |
| 642 | "name": "derp", |
| 643 | "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 644 | "flavorRef": "1", |
| 645 | "metadata": { |
| 646 | "abc": "def" |
| 647 | } |
| 648 | } |
| 649 | }`) |
| 650 | |
| 651 | w.WriteHeader(http.StatusAccepted) |
| 652 | w.Header().Add("Content-Type", "application/json") |
| 653 | fmt.Fprintf(w, response) |
| 654 | }) |
| 655 | } |
| 656 | |
Ash Wilson | a70510a | 2014-10-23 11:54:03 -0400 | [diff] [blame] | 657 | // HandleServerListSuccessfully sets up the test server to respond to a server List request. |
| 658 | func HandleServerListSuccessfully(t *testing.T) { |
| 659 | th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) { |
| 660 | th.TestMethod(t, r, "GET") |
| 661 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 662 | |
| 663 | w.Header().Add("Content-Type", "application/json") |
| 664 | r.ParseForm() |
| 665 | marker := r.Form.Get("marker") |
| 666 | switch marker { |
| 667 | case "": |
| 668 | fmt.Fprintf(w, ServerListBody) |
| 669 | case "9e5476bd-a4ec-4653-93d6-72c93aa682ba": |
| 670 | fmt.Fprintf(w, `{ "servers": [] }`) |
| 671 | default: |
| 672 | t.Fatalf("/servers/detail invoked with unexpected marker=[%s]", marker) |
| 673 | } |
| 674 | }) |
| 675 | } |
| 676 | |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 677 | // HandleServerDeletionSuccessfully sets up the test server to respond to a server deletion request. |
| 678 | func HandleServerDeletionSuccessfully(t *testing.T) { |
| 679 | th.Mux.HandleFunc("/servers/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) { |
| 680 | th.TestMethod(t, r, "DELETE") |
| 681 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 682 | |
| 683 | w.WriteHeader(http.StatusNoContent) |
| 684 | }) |
| 685 | } |
Ash Wilson | 1c1eb88 | 2014-10-21 18:14:31 -0400 | [diff] [blame] | 686 | |
Rickard von Essen | 5b8bbff | 2016-02-16 07:48:20 +0100 | [diff] [blame] | 687 | // HandleServerForceDeletionSuccessfully sets up the test server to respond to a server force deletion |
| 688 | // request. |
Ian Duffy | 370c430 | 2016-01-21 10:44:56 +0000 | [diff] [blame] | 689 | func HandleServerForceDeletionSuccessfully(t *testing.T) { |
| 690 | th.Mux.HandleFunc("/servers/asdfasdfasdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 691 | th.TestMethod(t, r, "POST") |
| 692 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 693 | th.TestJSONRequest(t, r, `{ "forceDelete": "" }`) |
| 694 | |
| 695 | w.WriteHeader(http.StatusAccepted) |
| 696 | }) |
| 697 | } |
| 698 | |
Ash Wilson | 189c95c | 2014-10-23 11:41:35 -0400 | [diff] [blame] | 699 | // HandleServerGetSuccessfully sets up the test server to respond to a server Get request. |
| 700 | func HandleServerGetSuccessfully(t *testing.T) { |
| 701 | th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) { |
| 702 | th.TestMethod(t, r, "GET") |
| 703 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 704 | th.TestHeader(t, r, "Accept", "application/json") |
| 705 | |
| 706 | fmt.Fprintf(w, SingleServerBody) |
| 707 | }) |
| 708 | } |
| 709 | |
| 710 | // HandleServerUpdateSuccessfully sets up the test server to respond to a server Update request. |
| 711 | func HandleServerUpdateSuccessfully(t *testing.T) { |
| 712 | th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) { |
| 713 | th.TestMethod(t, r, "PUT") |
| 714 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 715 | th.TestHeader(t, r, "Accept", "application/json") |
| 716 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 717 | th.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`) |
| 718 | |
| 719 | fmt.Fprintf(w, SingleServerBody) |
| 720 | }) |
| 721 | } |
| 722 | |
Ash Wilson | 1c1eb88 | 2014-10-21 18:14:31 -0400 | [diff] [blame] | 723 | // HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password |
| 724 | // change request. |
| 725 | func HandleAdminPasswordChangeSuccessfully(t *testing.T) { |
| 726 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 727 | th.TestMethod(t, r, "POST") |
| 728 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 729 | th.TestJSONRequest(t, r, `{ "changePassword": { "adminPass": "new-password" } }`) |
| 730 | |
| 731 | w.WriteHeader(http.StatusAccepted) |
| 732 | }) |
| 733 | } |
Ash Wilson | 2295ba5 | 2014-10-21 18:19:28 -0400 | [diff] [blame] | 734 | |
| 735 | // HandleRebootSuccessfully sets up the test server to respond to a reboot request with success. |
| 736 | func HandleRebootSuccessfully(t *testing.T) { |
| 737 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 738 | th.TestMethod(t, r, "POST") |
| 739 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 740 | th.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`) |
| 741 | |
| 742 | w.WriteHeader(http.StatusAccepted) |
| 743 | }) |
| 744 | } |
Ash Wilson | acf49c6 | 2014-10-21 18:25:11 -0400 | [diff] [blame] | 745 | |
| 746 | // HandleRebuildSuccessfully sets up the test server to respond to a rebuild request with success. |
| 747 | func HandleRebuildSuccessfully(t *testing.T, response string) { |
| 748 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 749 | th.TestMethod(t, r, "POST") |
| 750 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 751 | th.TestJSONRequest(t, r, ` |
| 752 | { |
| 753 | "rebuild": { |
| 754 | "name": "new-name", |
| 755 | "adminPass": "swordfish", |
| 756 | "imageRef": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 757 | "accessIPv4": "1.2.3.4" |
| 758 | } |
| 759 | } |
| 760 | `) |
| 761 | |
| 762 | w.WriteHeader(http.StatusAccepted) |
| 763 | w.Header().Add("Content-Type", "application/json") |
| 764 | fmt.Fprintf(w, response) |
| 765 | }) |
| 766 | } |
Alex Gaynor | fa8fbeb | 2014-11-13 13:39:31 -0800 | [diff] [blame] | 767 | |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 768 | // 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] | 769 | func HandleServerRescueSuccessfully(t *testing.T) { |
| 770 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 771 | th.TestMethod(t, r, "POST") |
| 772 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 773 | th.TestJSONRequest(t, r, `{ "rescue": { "adminPass": "1234567890" } }`) |
| 774 | |
| 775 | w.WriteHeader(http.StatusOK) |
| 776 | w.Write([]byte(`{ "adminPass": "1234567890" }`)) |
| 777 | }) |
| 778 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 779 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 780 | // HandleMetadatumGetSuccessfully sets up the test server to respond to a metadatum Get request. |
| 781 | func HandleMetadatumGetSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 782 | th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) { |
| 783 | th.TestMethod(t, r, "GET") |
| 784 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 785 | th.TestHeader(t, r, "Accept", "application/json") |
| 786 | |
| 787 | w.WriteHeader(http.StatusOK) |
| 788 | w.Header().Add("Content-Type", "application/json") |
| 789 | w.Write([]byte(`{ "meta": {"foo":"bar"}}`)) |
| 790 | }) |
| 791 | } |
| 792 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 793 | // HandleMetadatumCreateSuccessfully sets up the test server to respond to a metadatum Create request. |
| 794 | func HandleMetadatumCreateSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 795 | th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) { |
| 796 | th.TestMethod(t, r, "PUT") |
| 797 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 798 | th.TestJSONRequest(t, r, `{ |
| 799 | "meta": { |
| 800 | "foo": "bar" |
| 801 | } |
| 802 | }`) |
| 803 | |
| 804 | w.WriteHeader(http.StatusOK) |
| 805 | w.Header().Add("Content-Type", "application/json") |
| 806 | w.Write([]byte(`{ "meta": {"foo":"bar"}}`)) |
| 807 | }) |
| 808 | } |
| 809 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 810 | // HandleMetadatumDeleteSuccessfully sets up the test server to respond to a metadatum Delete request. |
| 811 | func HandleMetadatumDeleteSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 812 | th.Mux.HandleFunc("/servers/1234asdf/metadata/foo", func(w http.ResponseWriter, r *http.Request) { |
| 813 | th.TestMethod(t, r, "DELETE") |
| 814 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 815 | |
| 816 | w.WriteHeader(http.StatusNoContent) |
| 817 | }) |
| 818 | } |
| 819 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 820 | // HandleMetadataGetSuccessfully sets up the test server to respond to a metadata Get request. |
| 821 | func HandleMetadataGetSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 822 | th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 823 | th.TestMethod(t, r, "GET") |
| 824 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 825 | th.TestHeader(t, r, "Accept", "application/json") |
| 826 | |
| 827 | w.WriteHeader(http.StatusOK) |
| 828 | w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`)) |
| 829 | }) |
| 830 | } |
| 831 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 832 | // HandleMetadataResetSuccessfully sets up the test server to respond to a metadata Create request. |
| 833 | func HandleMetadataResetSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 834 | th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 835 | th.TestMethod(t, r, "PUT") |
| 836 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 837 | th.TestJSONRequest(t, r, `{ |
| 838 | "metadata": { |
| 839 | "foo": "bar", |
| 840 | "this": "that" |
| 841 | } |
| 842 | }`) |
| 843 | |
| 844 | w.WriteHeader(http.StatusOK) |
| 845 | w.Header().Add("Content-Type", "application/json") |
| 846 | w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`)) |
| 847 | }) |
| 848 | } |
| 849 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 850 | // HandleMetadataUpdateSuccessfully sets up the test server to respond to a metadata Update request. |
| 851 | func HandleMetadataUpdateSuccessfully(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 852 | th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 853 | th.TestMethod(t, r, "POST") |
| 854 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 855 | th.TestJSONRequest(t, r, `{ |
| 856 | "metadata": { |
| 857 | "foo": "baz", |
| 858 | "this": "those" |
| 859 | } |
| 860 | }`) |
| 861 | |
| 862 | w.WriteHeader(http.StatusOK) |
| 863 | w.Header().Add("Content-Type", "application/json") |
| 864 | w.Write([]byte(`{ "metadata": {"foo":"baz", "this":"those"}}`)) |
| 865 | }) |
| 866 | } |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 867 | |
| 868 | // ListAddressesExpected represents an expected repsonse from a ListAddresses request. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 869 | var ListAddressesExpected = map[string][]servers.Address{ |
| 870 | "public": []servers.Address{ |
| 871 | { |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 872 | Version: 4, |
| 873 | Address: "80.56.136.39", |
| 874 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 875 | { |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 876 | Version: 6, |
| 877 | Address: "2001:4800:790e:510:be76:4eff:fe04:82a8", |
| 878 | }, |
| 879 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 880 | "private": []servers.Address{ |
| 881 | { |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 882 | Version: 4, |
| 883 | Address: "10.880.3.154", |
| 884 | }, |
| 885 | }, |
| 886 | } |
| 887 | |
| 888 | // HandleAddressListSuccessfully sets up the test server to respond to a ListAddresses request. |
| 889 | func HandleAddressListSuccessfully(t *testing.T) { |
| 890 | th.Mux.HandleFunc("/servers/asdfasdfasdf/ips", func(w http.ResponseWriter, r *http.Request) { |
| 891 | th.TestMethod(t, r, "GET") |
| 892 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 893 | |
| 894 | w.Header().Add("Content-Type", "application/json") |
| 895 | fmt.Fprintf(w, `{ |
| 896 | "addresses": { |
| 897 | "public": [ |
| 898 | { |
| 899 | "version": 4, |
| 900 | "addr": "50.56.176.35" |
| 901 | }, |
| 902 | { |
| 903 | "version": 6, |
| 904 | "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8" |
| 905 | } |
| 906 | ], |
| 907 | "private": [ |
| 908 | { |
| 909 | "version": 4, |
| 910 | "addr": "10.180.3.155" |
| 911 | } |
| 912 | ] |
| 913 | } |
| 914 | }`) |
| 915 | }) |
| 916 | } |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 917 | |
| 918 | // ListNetworkAddressesExpected represents an expected repsonse from a ListAddressesByNetwork request. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 919 | var ListNetworkAddressesExpected = []servers.Address{ |
| 920 | { |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 921 | Version: 4, |
| 922 | Address: "50.56.176.35", |
| 923 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 924 | { |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 925 | Version: 6, |
| 926 | Address: "2001:4800:780e:510:be76:4eff:fe04:84a8", |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 927 | }, |
| 928 | } |
| 929 | |
| 930 | // HandleNetworkAddressListSuccessfully sets up the test server to respond to a ListAddressesByNetwork request. |
| 931 | func HandleNetworkAddressListSuccessfully(t *testing.T) { |
| 932 | th.Mux.HandleFunc("/servers/asdfasdfasdf/ips/public", func(w http.ResponseWriter, r *http.Request) { |
| 933 | th.TestMethod(t, r, "GET") |
| 934 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 935 | |
| 936 | w.Header().Add("Content-Type", "application/json") |
| 937 | fmt.Fprintf(w, `{ |
| 938 | "public": [ |
| 939 | { |
| 940 | "version": 4, |
| 941 | "addr": "50.56.176.35" |
| 942 | }, |
| 943 | { |
| 944 | "version": 6, |
| 945 | "addr": "2001:4800:780e:510:be76:4eff:fe04:84a8" |
| 946 | } |
| 947 | ] |
| 948 | }`) |
| 949 | }) |
| 950 | } |
einarf | 2fc665e | 2015-04-16 20:16:21 +0000 | [diff] [blame] | 951 | |
| 952 | // HandleCreateServerImageSuccessfully sets up the test server to respond to a TestCreateServerImage request. |
| 953 | func HandleCreateServerImageSuccessfully(t *testing.T) { |
| 954 | th.Mux.HandleFunc("/servers/serverimage/action", func(w http.ResponseWriter, r *http.Request) { |
| 955 | th.TestMethod(t, r, "POST") |
| 956 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 957 | w.Header().Add("Location", "https://0.0.0.0/images/xxxx-xxxxx-xxxxx-xxxx") |
| 958 | w.WriteHeader(http.StatusAccepted) |
| 959 | }) |
| 960 | } |
| 961 | |
Rickard von Essen | 5b8bbff | 2016-02-16 07:48:20 +0100 | [diff] [blame] | 962 | // HandlePasswordGetSuccessfully sets up the test server to respond to a password Get request. |
| 963 | func HandlePasswordGetSuccessfully(t *testing.T) { |
| 964 | th.Mux.HandleFunc("/servers/1234asdf/os-server-password", func(w http.ResponseWriter, r *http.Request) { |
| 965 | th.TestMethod(t, r, "GET") |
| 966 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 967 | th.TestHeader(t, r, "Accept", "application/json") |
| 968 | |
| 969 | fmt.Fprintf(w, ServerPasswordBody) |
| 970 | }) |
| 971 | } |