Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame^] | 1 | // +build fixtures |
| 2 | |
| 3 | package servers |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | ) |
| 10 | |
| 11 | // ServerListBody contains the canned body of a servers.List response. |
| 12 | const ServerListBody = ` |
| 13 | { |
| 14 | "servers": [ |
| 15 | { |
| 16 | "status": "ACTIVE", |
| 17 | "updated": "2014-09-25T13:10:10Z", |
| 18 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 19 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 20 | "addresses": { |
| 21 | "private": [ |
| 22 | { |
| 23 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b", |
| 24 | "version": 4, |
| 25 | "addr": "10.0.0.32", |
| 26 | "OS-EXT-IPS:type": "fixed" |
| 27 | } |
| 28 | ] |
| 29 | }, |
| 30 | "links": [ |
| 31 | { |
| 32 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 33 | "rel": "self" |
| 34 | }, |
| 35 | { |
| 36 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 37 | "rel": "bookmark" |
| 38 | } |
| 39 | ], |
| 40 | "key_name": null, |
| 41 | "image": { |
| 42 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 43 | "links": [ |
| 44 | { |
| 45 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 46 | "rel": "bookmark" |
| 47 | } |
| 48 | ] |
| 49 | }, |
| 50 | "OS-EXT-STS:task_state": null, |
| 51 | "OS-EXT-STS:vm_state": "active", |
| 52 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001e", |
| 53 | "OS-SRV-USG:launched_at": "2014-09-25T13:10:10.000000", |
| 54 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 55 | "flavor": { |
| 56 | "id": "1", |
| 57 | "links": [ |
| 58 | { |
| 59 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 60 | "rel": "bookmark" |
| 61 | } |
| 62 | ] |
| 63 | }, |
| 64 | "id": "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 65 | "security_groups": [ |
| 66 | { |
| 67 | "name": "default" |
| 68 | } |
| 69 | ], |
| 70 | "OS-SRV-USG:terminated_at": null, |
| 71 | "OS-EXT-AZ:availability_zone": "nova", |
| 72 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 73 | "name": "herp", |
| 74 | "created": "2014-09-25T13:10:02Z", |
| 75 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 76 | "OS-DCF:diskConfig": "MANUAL", |
| 77 | "os-extended-volumes:volumes_attached": [], |
| 78 | "accessIPv4": "", |
| 79 | "accessIPv6": "", |
| 80 | "progress": 0, |
| 81 | "OS-EXT-STS:power_state": 1, |
| 82 | "config_drive": "", |
| 83 | "metadata": {} |
| 84 | }, |
| 85 | { |
| 86 | "status": "ACTIVE", |
| 87 | "updated": "2014-09-25T13:04:49Z", |
| 88 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 89 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 90 | "addresses": { |
| 91 | "private": [ |
| 92 | { |
| 93 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 94 | "version": 4, |
| 95 | "addr": "10.0.0.31", |
| 96 | "OS-EXT-IPS:type": "fixed" |
| 97 | } |
| 98 | ] |
| 99 | }, |
| 100 | "links": [ |
| 101 | { |
| 102 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 103 | "rel": "self" |
| 104 | }, |
| 105 | { |
| 106 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 107 | "rel": "bookmark" |
| 108 | } |
| 109 | ], |
| 110 | "key_name": null, |
| 111 | "image": { |
| 112 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 113 | "links": [ |
| 114 | { |
| 115 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 116 | "rel": "bookmark" |
| 117 | } |
| 118 | ] |
| 119 | }, |
| 120 | "OS-EXT-STS:task_state": null, |
| 121 | "OS-EXT-STS:vm_state": "active", |
| 122 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d", |
| 123 | "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000", |
| 124 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 125 | "flavor": { |
| 126 | "id": "1", |
| 127 | "links": [ |
| 128 | { |
| 129 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 130 | "rel": "bookmark" |
| 131 | } |
| 132 | ] |
| 133 | }, |
| 134 | "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 135 | "security_groups": [ |
| 136 | { |
| 137 | "name": "default" |
| 138 | } |
| 139 | ], |
| 140 | "OS-SRV-USG:terminated_at": null, |
| 141 | "OS-EXT-AZ:availability_zone": "nova", |
| 142 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 143 | "name": "derp", |
| 144 | "created": "2014-09-25T13:04:41Z", |
| 145 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 146 | "OS-DCF:diskConfig": "MANUAL", |
| 147 | "os-extended-volumes:volumes_attached": [], |
| 148 | "accessIPv4": "", |
| 149 | "accessIPv6": "", |
| 150 | "progress": 0, |
| 151 | "OS-EXT-STS:power_state": 1, |
| 152 | "config_drive": "", |
| 153 | "metadata": {} |
| 154 | } |
| 155 | ] |
| 156 | } |
| 157 | ` |
| 158 | |
| 159 | // SingleServerBody is the canned body of a Get request on an existing server. |
| 160 | const SingleServerBody = ` |
| 161 | { |
| 162 | "server": { |
| 163 | "status": "ACTIVE", |
| 164 | "updated": "2014-09-25T13:04:49Z", |
| 165 | "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 166 | "OS-EXT-SRV-ATTR:host": "devstack", |
| 167 | "addresses": { |
| 168 | "private": [ |
| 169 | { |
| 170 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 171 | "version": 4, |
| 172 | "addr": "10.0.0.31", |
| 173 | "OS-EXT-IPS:type": "fixed" |
| 174 | } |
| 175 | ] |
| 176 | }, |
| 177 | "links": [ |
| 178 | { |
| 179 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 180 | "rel": "self" |
| 181 | }, |
| 182 | { |
| 183 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 184 | "rel": "bookmark" |
| 185 | } |
| 186 | ], |
| 187 | "key_name": null, |
| 188 | "image": { |
| 189 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 190 | "links": [ |
| 191 | { |
| 192 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 193 | "rel": "bookmark" |
| 194 | } |
| 195 | ] |
| 196 | }, |
| 197 | "OS-EXT-STS:task_state": null, |
| 198 | "OS-EXT-STS:vm_state": "active", |
| 199 | "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d", |
| 200 | "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000", |
| 201 | "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack", |
| 202 | "flavor": { |
| 203 | "id": "1", |
| 204 | "links": [ |
| 205 | { |
| 206 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 207 | "rel": "bookmark" |
| 208 | } |
| 209 | ] |
| 210 | }, |
| 211 | "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 212 | "security_groups": [ |
| 213 | { |
| 214 | "name": "default" |
| 215 | } |
| 216 | ], |
| 217 | "OS-SRV-USG:terminated_at": null, |
| 218 | "OS-EXT-AZ:availability_zone": "nova", |
| 219 | "user_id": "9349aff8be7545ac9d2f1d00999a23cd", |
| 220 | "name": "derp", |
| 221 | "created": "2014-09-25T13:04:41Z", |
| 222 | "tenant_id": "fcad67a6189847c4aecfa3c81a05783b", |
| 223 | "OS-DCF:diskConfig": "MANUAL", |
| 224 | "os-extended-volumes:volumes_attached": [], |
| 225 | "accessIPv4": "", |
| 226 | "accessIPv6": "", |
| 227 | "progress": 0, |
| 228 | "OS-EXT-STS:power_state": 1, |
| 229 | "config_drive": "", |
| 230 | "metadata": {} |
| 231 | } |
| 232 | } |
| 233 | ` |
| 234 | |
| 235 | var ( |
| 236 | // ServerHerp is a Server struct that should correspond to the first result in ServerListBody. |
| 237 | ServerHerp = Server{ |
| 238 | Status: "ACTIVE", |
| 239 | Updated: "2014-09-25T13:10:10Z", |
| 240 | HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 241 | Addresses: map[string]interface{}{ |
| 242 | "private": []interface{}{ |
| 243 | map[string]interface{}{ |
| 244 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b", |
| 245 | "version": float64(4), |
| 246 | "addr": "10.0.0.32", |
| 247 | "OS-EXT-IPS:type": "fixed", |
| 248 | }, |
| 249 | }, |
| 250 | }, |
| 251 | Links: []interface{}{ |
| 252 | map[string]interface{}{ |
| 253 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 254 | "rel": "self", |
| 255 | }, |
| 256 | map[string]interface{}{ |
| 257 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 258 | "rel": "bookmark", |
| 259 | }, |
| 260 | }, |
| 261 | Image: map[string]interface{}{ |
| 262 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 263 | "links": []interface{}{ |
| 264 | map[string]interface{}{ |
| 265 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 266 | "rel": "bookmark", |
| 267 | }, |
| 268 | }, |
| 269 | }, |
| 270 | Flavor: map[string]interface{}{ |
| 271 | "id": "1", |
| 272 | "links": []interface{}{ |
| 273 | map[string]interface{}{ |
| 274 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 275 | "rel": "bookmark", |
| 276 | }, |
| 277 | }, |
| 278 | }, |
| 279 | ID: "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5", |
| 280 | UserID: "9349aff8be7545ac9d2f1d00999a23cd", |
| 281 | Name: "herp", |
| 282 | Created: "2014-09-25T13:10:02Z", |
| 283 | TenantID: "fcad67a6189847c4aecfa3c81a05783b", |
| 284 | Metadata: map[string]interface{}{}, |
| 285 | } |
| 286 | |
| 287 | // ServerDerp is a Server struct that should correspond to the second server in ServerListBody. |
| 288 | ServerDerp = Server{ |
| 289 | Status: "ACTIVE", |
| 290 | Updated: "2014-09-25T13:04:49Z", |
| 291 | HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362", |
| 292 | Addresses: map[string]interface{}{ |
| 293 | "private": []interface{}{ |
| 294 | map[string]interface{}{ |
| 295 | "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be", |
| 296 | "version": float64(4), |
| 297 | "addr": "10.0.0.31", |
| 298 | "OS-EXT-IPS:type": "fixed", |
| 299 | }, |
| 300 | }, |
| 301 | }, |
| 302 | Links: []interface{}{ |
| 303 | map[string]interface{}{ |
| 304 | "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 305 | "rel": "self", |
| 306 | }, |
| 307 | map[string]interface{}{ |
| 308 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 309 | "rel": "bookmark", |
| 310 | }, |
| 311 | }, |
| 312 | Image: map[string]interface{}{ |
| 313 | "id": "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 314 | "links": []interface{}{ |
| 315 | map[string]interface{}{ |
| 316 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 317 | "rel": "bookmark", |
| 318 | }, |
| 319 | }, |
| 320 | }, |
| 321 | Flavor: map[string]interface{}{ |
| 322 | "id": "1", |
| 323 | "links": []interface{}{ |
| 324 | map[string]interface{}{ |
| 325 | "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1", |
| 326 | "rel": "bookmark", |
| 327 | }, |
| 328 | }, |
| 329 | }, |
| 330 | ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba", |
| 331 | UserID: "9349aff8be7545ac9d2f1d00999a23cd", |
| 332 | Name: "derp", |
| 333 | Created: "2014-09-25T13:04:41Z", |
| 334 | TenantID: "fcad67a6189847c4aecfa3c81a05783b", |
| 335 | Metadata: map[string]interface{}{}, |
| 336 | } |
| 337 | ) |
| 338 | |
| 339 | // CheckServerEquals provides more fine-grained failures when Servers differ, because Server structs |
| 340 | // are too damn big to compare by eye. |
| 341 | func CheckServerEquals(t *testing.T, expected Server, actual Server) { |
| 342 | th.CheckEquals(t, expected.ID, actual.ID) |
| 343 | th.CheckEquals(t, expected.TenantID, actual.TenantID) |
| 344 | th.CheckEquals(t, expected.UserID, actual.UserID) |
| 345 | th.CheckEquals(t, expected.Name, actual.Name) |
| 346 | th.CheckEquals(t, expected.Updated, actual.Updated) |
| 347 | th.CheckEquals(t, expected.Created, actual.Created) |
| 348 | th.CheckEquals(t, expected.HostID, actual.HostID) |
| 349 | th.CheckEquals(t, expected.Status, actual.Status) |
| 350 | th.CheckEquals(t, expected.Progress, actual.Progress) |
| 351 | th.CheckEquals(t, expected.AccessIPv4, actual.AccessIPv4) |
| 352 | th.CheckEquals(t, expected.AccessIPv6, actual.AccessIPv6) |
| 353 | th.CheckDeepEquals(t, expected.Image, actual.Image) |
| 354 | th.CheckDeepEquals(t, expected.Flavor, actual.Flavor) |
| 355 | th.CheckDeepEquals(t, expected.Addresses, actual.Addresses) |
| 356 | th.CheckDeepEquals(t, expected.Metadata, actual.Metadata) |
| 357 | th.CheckDeepEquals(t, expected.Links, actual.Links) |
| 358 | th.CheckEquals(t, expected.KeyName, actual.KeyName) |
| 359 | th.CheckEquals(t, expected.AdminPass, actual.AdminPass) |
| 360 | } |