Begin moving compute fixtures into fixtures.go.
diff --git a/openstack/compute/v2/servers/data_test.go b/openstack/compute/v2/servers/data_test.go
deleted file mode 100644
index d3a0ee0..0000000
--- a/openstack/compute/v2/servers/data_test.go
+++ /dev/null
@@ -1,328 +0,0 @@
-package servers
-
-// Recorded responses for the server resource.
-
-const (
- serverListBody = `
- {
- "servers": [
- {
- "status": "ACTIVE",
- "updated": "2014-09-25T13:10:10Z",
- "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
- "OS-EXT-SRV-ATTR:host": "devstack",
- "addresses": {
- "private": [
- {
- "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
- "version": 4,
- "addr": "10.0.0.32",
- "OS-EXT-IPS:type": "fixed"
- }
- ]
- },
- "links": [
- {
- "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
- "rel": "self"
- },
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
- "rel": "bookmark"
- }
- ],
- "key_name": null,
- "image": {
- "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
- "links": [
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
- "rel": "bookmark"
- }
- ]
- },
- "OS-EXT-STS:task_state": null,
- "OS-EXT-STS:vm_state": "active",
- "OS-EXT-SRV-ATTR:instance_name": "instance-0000001e",
- "OS-SRV-USG:launched_at": "2014-09-25T13:10:10.000000",
- "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
- "flavor": {
- "id": "1",
- "links": [
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
- "rel": "bookmark"
- }
- ]
- },
- "id": "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
- "security_groups": [
- {
- "name": "default"
- }
- ],
- "OS-SRV-USG:terminated_at": null,
- "OS-EXT-AZ:availability_zone": "nova",
- "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
- "name": "herp",
- "created": "2014-09-25T13:10:02Z",
- "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
- "OS-DCF:diskConfig": "MANUAL",
- "os-extended-volumes:volumes_attached": [],
- "accessIPv4": "",
- "accessIPv6": "",
- "progress": 0,
- "OS-EXT-STS:power_state": 1,
- "config_drive": "",
- "metadata": {}
- },
- {
- "status": "ACTIVE",
- "updated": "2014-09-25T13:04:49Z",
- "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
- "OS-EXT-SRV-ATTR:host": "devstack",
- "addresses": {
- "private": [
- {
- "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
- "version": 4,
- "addr": "10.0.0.31",
- "OS-EXT-IPS:type": "fixed"
- }
- ]
- },
- "links": [
- {
- "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "rel": "self"
- },
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "rel": "bookmark"
- }
- ],
- "key_name": null,
- "image": {
- "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
- "links": [
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
- "rel": "bookmark"
- }
- ]
- },
- "OS-EXT-STS:task_state": null,
- "OS-EXT-STS:vm_state": "active",
- "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d",
- "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
- "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
- "flavor": {
- "id": "1",
- "links": [
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
- "rel": "bookmark"
- }
- ]
- },
- "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "security_groups": [
- {
- "name": "default"
- }
- ],
- "OS-SRV-USG:terminated_at": null,
- "OS-EXT-AZ:availability_zone": "nova",
- "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
- "name": "derp",
- "created": "2014-09-25T13:04:41Z",
- "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
- "OS-DCF:diskConfig": "MANUAL",
- "os-extended-volumes:volumes_attached": [],
- "accessIPv4": "",
- "accessIPv6": "",
- "progress": 0,
- "OS-EXT-STS:power_state": 1,
- "config_drive": "",
- "metadata": {}
- }
- ]
- }
- `
-
- singleServerBody = `
- {
- "server": {
- "status": "ACTIVE",
- "updated": "2014-09-25T13:04:49Z",
- "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
- "OS-EXT-SRV-ATTR:host": "devstack",
- "addresses": {
- "private": [
- {
- "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
- "version": 4,
- "addr": "10.0.0.31",
- "OS-EXT-IPS:type": "fixed"
- }
- ]
- },
- "links": [
- {
- "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "rel": "self"
- },
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "rel": "bookmark"
- }
- ],
- "key_name": null,
- "image": {
- "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
- "links": [
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
- "rel": "bookmark"
- }
- ]
- },
- "OS-EXT-STS:task_state": null,
- "OS-EXT-STS:vm_state": "active",
- "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d",
- "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
- "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
- "flavor": {
- "id": "1",
- "links": [
- {
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
- "rel": "bookmark"
- }
- ]
- },
- "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "security_groups": [
- {
- "name": "default"
- }
- ],
- "OS-SRV-USG:terminated_at": null,
- "OS-EXT-AZ:availability_zone": "nova",
- "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
- "name": "derp",
- "created": "2014-09-25T13:04:41Z",
- "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
- "OS-DCF:diskConfig": "MANUAL",
- "os-extended-volumes:volumes_attached": [],
- "accessIPv4": "",
- "accessIPv6": "",
- "progress": 0,
- "OS-EXT-STS:power_state": 1,
- "config_drive": "",
- "metadata": {}
- }
- }
- `
-)
-
-var (
- serverHerp = Server{
- Status: "ACTIVE",
- Updated: "2014-09-25T13:10:10Z",
- HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
- Addresses: map[string]interface{}{
- "private": []interface{}{
- map[string]interface{}{
- "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
- "version": float64(4),
- "addr": "10.0.0.32",
- "OS-EXT-IPS:type": "fixed",
- },
- },
- },
- Links: []interface{}{
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
- "rel": "self",
- },
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
- "rel": "bookmark",
- },
- },
- Image: map[string]interface{}{
- "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
- "links": []interface{}{
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
- "rel": "bookmark",
- },
- },
- },
- Flavor: map[string]interface{}{
- "id": "1",
- "links": []interface{}{
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
- "rel": "bookmark",
- },
- },
- },
- ID: "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
- UserID: "9349aff8be7545ac9d2f1d00999a23cd",
- Name: "herp",
- Created: "2014-09-25T13:10:02Z",
- TenantID: "fcad67a6189847c4aecfa3c81a05783b",
- Metadata: map[string]interface{}{},
- }
- serverDerp = Server{
- Status: "ACTIVE",
- Updated: "2014-09-25T13:04:49Z",
- HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
- Addresses: map[string]interface{}{
- "private": []interface{}{
- map[string]interface{}{
- "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
- "version": float64(4),
- "addr": "10.0.0.31",
- "OS-EXT-IPS:type": "fixed",
- },
- },
- },
- Links: []interface{}{
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "rel": "self",
- },
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- "rel": "bookmark",
- },
- },
- Image: map[string]interface{}{
- "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
- "links": []interface{}{
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
- "rel": "bookmark",
- },
- },
- },
- Flavor: map[string]interface{}{
- "id": "1",
- "links": []interface{}{
- map[string]interface{}{
- "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
- "rel": "bookmark",
- },
- },
- },
- ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
- UserID: "9349aff8be7545ac9d2f1d00999a23cd",
- Name: "derp",
- Created: "2014-09-25T13:04:41Z",
- TenantID: "fcad67a6189847c4aecfa3c81a05783b",
- Metadata: map[string]interface{}{},
- }
-)
diff --git a/openstack/compute/v2/servers/fixtures.go b/openstack/compute/v2/servers/fixtures.go
new file mode 100644
index 0000000..2ea05e9
--- /dev/null
+++ b/openstack/compute/v2/servers/fixtures.go
@@ -0,0 +1,360 @@
+// +build fixtures
+
+package servers
+
+import (
+ "testing"
+
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+// ServerListBody contains the canned body of a servers.List response.
+const ServerListBody = `
+{
+ "servers": [
+ {
+ "status": "ACTIVE",
+ "updated": "2014-09-25T13:10:10Z",
+ "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
+ "OS-EXT-SRV-ATTR:host": "devstack",
+ "addresses": {
+ "private": [
+ {
+ "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
+ "version": 4,
+ "addr": "10.0.0.32",
+ "OS-EXT-IPS:type": "fixed"
+ }
+ ]
+ },
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
+ "rel": "self"
+ },
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
+ "rel": "bookmark"
+ }
+ ],
+ "key_name": null,
+ "image": {
+ "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "OS-EXT-STS:task_state": null,
+ "OS-EXT-STS:vm_state": "active",
+ "OS-EXT-SRV-ATTR:instance_name": "instance-0000001e",
+ "OS-SRV-USG:launched_at": "2014-09-25T13:10:10.000000",
+ "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "id": "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
+ "security_groups": [
+ {
+ "name": "default"
+ }
+ ],
+ "OS-SRV-USG:terminated_at": null,
+ "OS-EXT-AZ:availability_zone": "nova",
+ "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
+ "name": "herp",
+ "created": "2014-09-25T13:10:02Z",
+ "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
+ "OS-DCF:diskConfig": "MANUAL",
+ "os-extended-volumes:volumes_attached": [],
+ "accessIPv4": "",
+ "accessIPv6": "",
+ "progress": 0,
+ "OS-EXT-STS:power_state": 1,
+ "config_drive": "",
+ "metadata": {}
+ },
+ {
+ "status": "ACTIVE",
+ "updated": "2014-09-25T13:04:49Z",
+ "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
+ "OS-EXT-SRV-ATTR:host": "devstack",
+ "addresses": {
+ "private": [
+ {
+ "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
+ "version": 4,
+ "addr": "10.0.0.31",
+ "OS-EXT-IPS:type": "fixed"
+ }
+ ]
+ },
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "rel": "self"
+ },
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "rel": "bookmark"
+ }
+ ],
+ "key_name": null,
+ "image": {
+ "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "OS-EXT-STS:task_state": null,
+ "OS-EXT-STS:vm_state": "active",
+ "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d",
+ "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
+ "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "security_groups": [
+ {
+ "name": "default"
+ }
+ ],
+ "OS-SRV-USG:terminated_at": null,
+ "OS-EXT-AZ:availability_zone": "nova",
+ "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
+ "name": "derp",
+ "created": "2014-09-25T13:04:41Z",
+ "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
+ "OS-DCF:diskConfig": "MANUAL",
+ "os-extended-volumes:volumes_attached": [],
+ "accessIPv4": "",
+ "accessIPv6": "",
+ "progress": 0,
+ "OS-EXT-STS:power_state": 1,
+ "config_drive": "",
+ "metadata": {}
+ }
+ ]
+}
+`
+
+// SingleServerBody is the canned body of a Get request on an existing server.
+const SingleServerBody = `
+{
+ "server": {
+ "status": "ACTIVE",
+ "updated": "2014-09-25T13:04:49Z",
+ "hostId": "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
+ "OS-EXT-SRV-ATTR:host": "devstack",
+ "addresses": {
+ "private": [
+ {
+ "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
+ "version": 4,
+ "addr": "10.0.0.31",
+ "OS-EXT-IPS:type": "fixed"
+ }
+ ]
+ },
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "rel": "self"
+ },
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "rel": "bookmark"
+ }
+ ],
+ "key_name": null,
+ "image": {
+ "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "OS-EXT-STS:task_state": null,
+ "OS-EXT-STS:vm_state": "active",
+ "OS-EXT-SRV-ATTR:instance_name": "instance-0000001d",
+ "OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
+ "OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "security_groups": [
+ {
+ "name": "default"
+ }
+ ],
+ "OS-SRV-USG:terminated_at": null,
+ "OS-EXT-AZ:availability_zone": "nova",
+ "user_id": "9349aff8be7545ac9d2f1d00999a23cd",
+ "name": "derp",
+ "created": "2014-09-25T13:04:41Z",
+ "tenant_id": "fcad67a6189847c4aecfa3c81a05783b",
+ "OS-DCF:diskConfig": "MANUAL",
+ "os-extended-volumes:volumes_attached": [],
+ "accessIPv4": "",
+ "accessIPv6": "",
+ "progress": 0,
+ "OS-EXT-STS:power_state": 1,
+ "config_drive": "",
+ "metadata": {}
+ }
+}
+`
+
+var (
+ // ServerHerp is a Server struct that should correspond to the first result in ServerListBody.
+ ServerHerp = Server{
+ Status: "ACTIVE",
+ Updated: "2014-09-25T13:10:10Z",
+ HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
+ Addresses: map[string]interface{}{
+ "private": []interface{}{
+ map[string]interface{}{
+ "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:1b:2b",
+ "version": float64(4),
+ "addr": "10.0.0.32",
+ "OS-EXT-IPS:type": "fixed",
+ },
+ },
+ },
+ Links: []interface{}{
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
+ "rel": "self",
+ },
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
+ "rel": "bookmark",
+ },
+ },
+ Image: map[string]interface{}{
+ "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
+ "links": []interface{}{
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
+ "rel": "bookmark",
+ },
+ },
+ },
+ Flavor: map[string]interface{}{
+ "id": "1",
+ "links": []interface{}{
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
+ "rel": "bookmark",
+ },
+ },
+ },
+ ID: "ef079b0c-e610-4dfb-b1aa-b49f07ac48e5",
+ UserID: "9349aff8be7545ac9d2f1d00999a23cd",
+ Name: "herp",
+ Created: "2014-09-25T13:10:02Z",
+ TenantID: "fcad67a6189847c4aecfa3c81a05783b",
+ Metadata: map[string]interface{}{},
+ }
+
+ // ServerDerp is a Server struct that should correspond to the second server in ServerListBody.
+ ServerDerp = Server{
+ Status: "ACTIVE",
+ Updated: "2014-09-25T13:04:49Z",
+ HostID: "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362",
+ Addresses: map[string]interface{}{
+ "private": []interface{}{
+ map[string]interface{}{
+ "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:9e:89:be",
+ "version": float64(4),
+ "addr": "10.0.0.31",
+ "OS-EXT-IPS:type": "fixed",
+ },
+ },
+ },
+ Links: []interface{}{
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/v2/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "rel": "self",
+ },
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/servers/9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ "rel": "bookmark",
+ },
+ },
+ Image: map[string]interface{}{
+ "id": "f90f6034-2570-4974-8351-6b49732ef2eb",
+ "links": []interface{}{
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb",
+ "rel": "bookmark",
+ },
+ },
+ },
+ Flavor: map[string]interface{}{
+ "id": "1",
+ "links": []interface{}{
+ map[string]interface{}{
+ "href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
+ "rel": "bookmark",
+ },
+ },
+ },
+ ID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
+ UserID: "9349aff8be7545ac9d2f1d00999a23cd",
+ Name: "derp",
+ Created: "2014-09-25T13:04:41Z",
+ TenantID: "fcad67a6189847c4aecfa3c81a05783b",
+ Metadata: map[string]interface{}{},
+ }
+)
+
+// CheckServerEquals provides more fine-grained failures when Servers differ, because Server structs
+// are too damn big to compare by eye.
+func CheckServerEquals(t *testing.T, expected Server, actual Server) {
+ th.CheckEquals(t, expected.ID, actual.ID)
+ th.CheckEquals(t, expected.TenantID, actual.TenantID)
+ th.CheckEquals(t, expected.UserID, actual.UserID)
+ th.CheckEquals(t, expected.Name, actual.Name)
+ th.CheckEquals(t, expected.Updated, actual.Updated)
+ th.CheckEquals(t, expected.Created, actual.Created)
+ th.CheckEquals(t, expected.HostID, actual.HostID)
+ th.CheckEquals(t, expected.Status, actual.Status)
+ th.CheckEquals(t, expected.Progress, actual.Progress)
+ th.CheckEquals(t, expected.AccessIPv4, actual.AccessIPv4)
+ th.CheckEquals(t, expected.AccessIPv6, actual.AccessIPv6)
+ th.CheckDeepEquals(t, expected.Image, actual.Image)
+ th.CheckDeepEquals(t, expected.Flavor, actual.Flavor)
+ th.CheckDeepEquals(t, expected.Addresses, actual.Addresses)
+ th.CheckDeepEquals(t, expected.Metadata, actual.Metadata)
+ th.CheckDeepEquals(t, expected.Links, actual.Links)
+ th.CheckEquals(t, expected.KeyName, actual.KeyName)
+ th.CheckEquals(t, expected.AdminPass, actual.AdminPass)
+}
diff --git a/openstack/compute/v2/servers/requests_test.go b/openstack/compute/v2/servers/requests_test.go
index 0db92f9..5e38433 100644
--- a/openstack/compute/v2/servers/requests_test.go
+++ b/openstack/compute/v2/servers/requests_test.go
@@ -6,24 +6,24 @@
"testing"
"github.com/rackspace/gophercloud/pagination"
- "github.com/rackspace/gophercloud/testhelper"
- fake "github.com/rackspace/gophercloud/testhelper/client"
+ th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
)
func TestListServers(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
- fmt.Fprintf(w, serverListBody)
+ fmt.Fprintf(w, ServerListBody)
case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
fmt.Fprintf(w, `{ "servers": [] }`)
default:
@@ -32,7 +32,7 @@
})
pages := 0
- err := List(fake.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := ExtractServers(page)
@@ -43,13 +43,13 @@
if len(actual) != 2 {
t.Fatalf("Expected 2 servers, got %d", len(actual))
}
- equalServers(t, serverHerp, actual[0])
- equalServers(t, serverDerp, actual[1])
+ CheckServerEquals(t, ServerHerp, actual[0])
+ CheckServerEquals(t, ServerDerp, actual[1])
return true, nil
})
- testhelper.AssertNoErr(t, err)
+ th.AssertNoErr(t, err)
if pages != 1 {
t.Errorf("Expected 1 page, saw %d", pages)
@@ -57,13 +57,13 @@
}
func TestCreateServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `{
+ th.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
"server": {
"name": "derp",
"imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb",
@@ -73,10 +73,10 @@
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
- fmt.Fprintf(w, singleServerBody)
+ fmt.Fprintf(w, SingleServerBody)
})
- client := fake.ServiceClient()
+ client := client.ServiceClient()
actual, err := Create(client, CreateOpts{
Name: "derp",
ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb",
@@ -86,21 +86,21 @@
t.Fatalf("Unexpected Create error: %v", err)
}
- equalServers(t, serverDerp, *actual)
+ CheckServerEquals(t, ServerDerp, *actual)
}
func TestDeleteServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "DELETE")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.Mux.HandleFunc("/servers/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
- client := fake.ServiceClient()
+ client := client.ServiceClient()
err := Delete(client, "asdfasdfasdf")
if err != nil {
t.Fatalf("Unexpected Delete error: %v", err)
@@ -108,89 +108,89 @@
}
func TestGetServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestHeader(t, r, "Accept", "application/json")
+ th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
- fmt.Fprintf(w, singleServerBody)
+ fmt.Fprintf(w, SingleServerBody)
})
- client := fake.ServiceClient()
+ client := client.ServiceClient()
actual, err := Get(client, "1234asdf").Extract()
if err != nil {
t.Fatalf("Unexpected Get error: %v", err)
}
- equalServers(t, serverDerp, *actual)
+ CheckServerEquals(t, ServerDerp, *actual)
}
func TestUpdateServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "PUT")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestHeader(t, r, "Accept", "application/json")
- testhelper.TestHeader(t, r, "Content-Type", "application/json")
- testhelper.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`)
+ th.Mux.HandleFunc("/servers/1234asdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestJSONRequest(t, r, `{ "server": { "name": "new-name" } }`)
- fmt.Fprintf(w, singleServerBody)
+ fmt.Fprintf(w, SingleServerBody)
})
- client := fake.ServiceClient()
+ client := client.ServiceClient()
actual, err := Update(client, "1234asdf", UpdateOpts{Name: "new-name"}).Extract()
if err != nil {
t.Fatalf("Unexpected Update error: %v", err)
}
- equalServers(t, serverDerp, *actual)
+ CheckServerEquals(t, ServerDerp, *actual)
}
func TestChangeServerAdminPassword(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `{ "changePassword": { "adminPass": "new-password" } }`)
+ th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{ "changePassword": { "adminPass": "new-password" } }`)
w.WriteHeader(http.StatusAccepted)
})
- res := ChangeAdminPassword(fake.ServiceClient(), "1234asdf", "new-password")
- testhelper.AssertNoErr(t, res.Err)
+ res := ChangeAdminPassword(client.ServiceClient(), "1234asdf", "new-password")
+ th.AssertNoErr(t, res.Err)
}
func TestRebootServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`)
+ th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{ "reboot": { "type": "SOFT" } }`)
w.WriteHeader(http.StatusAccepted)
})
- res := Reboot(fake.ServiceClient(), "1234asdf", SoftReboot)
- testhelper.AssertNoErr(t, res.Err)
+ res := Reboot(client.ServiceClient(), "1234asdf", SoftReboot)
+ th.AssertNoErr(t, res.Err)
}
func TestRebuildServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `
+ th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `
{
"rebuild": {
"name": "new-name",
@@ -203,7 +203,7 @@
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
- fmt.Fprintf(w, singleServerBody)
+ fmt.Fprintf(w, SingleServerBody)
})
opts := RebuildOpts{
@@ -213,56 +213,56 @@
AccessIPv4: "1.2.3.4",
}
- actual, err := Rebuild(fake.ServiceClient(), "1234asdf", opts).Extract()
- testhelper.AssertNoErr(t, err)
+ actual, err := Rebuild(client.ServiceClient(), "1234asdf", opts).Extract()
+ th.AssertNoErr(t, err)
- equalServers(t, serverDerp, *actual)
+ CheckServerEquals(t, ServerDerp, *actual)
}
func TestResizeServer(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `{ "resize": { "flavorRef": "2" } }`)
+ th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{ "resize": { "flavorRef": "2" } }`)
w.WriteHeader(http.StatusAccepted)
})
- res := Resize(fake.ServiceClient(), "1234asdf", "2")
- testhelper.AssertNoErr(t, res.Err)
+ res := Resize(client.ServiceClient(), "1234asdf", "2")
+ th.AssertNoErr(t, res.Err)
}
func TestConfirmResize(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `{ "confirmResize": null }`)
+ th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{ "confirmResize": null }`)
w.WriteHeader(http.StatusNoContent)
})
- res := ConfirmResize(fake.ServiceClient(), "1234asdf")
- testhelper.AssertNoErr(t, res.Err)
+ res := ConfirmResize(client.ServiceClient(), "1234asdf")
+ th.AssertNoErr(t, res.Err)
}
func TestRevertResize(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
- testhelper.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
- testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- testhelper.TestJSONRequest(t, r, `{ "revertResize": null }`)
+ th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{ "revertResize": null }`)
w.WriteHeader(http.StatusAccepted)
})
- res := RevertResize(fake.ServiceClient(), "1234asdf")
- testhelper.AssertNoErr(t, res.Err)
+ res := RevertResize(client.ServiceClient(), "1234asdf")
+ th.AssertNoErr(t, res.Err)
}
diff --git a/openstack/compute/v2/servers/servers_test.go b/openstack/compute/v2/servers/servers_test.go
deleted file mode 100644
index 590fc8b..0000000
--- a/openstack/compute/v2/servers/servers_test.go
+++ /dev/null
@@ -1,65 +0,0 @@
-package servers
-
-import (
- "reflect"
- "testing"
-)
-
-// This provides more fine-grained failures when Servers differ, because Server structs are too damn big to compare by eye.
-// FIXME I should absolutely refactor this into a general-purpose thing in testhelper.
-func equalServers(t *testing.T, expected Server, actual Server) {
- if expected.ID != actual.ID {
- t.Errorf("ID differs. expected=[%s], actual=[%s]", expected.ID, actual.ID)
- }
- if expected.TenantID != actual.TenantID {
- t.Errorf("TenantID differs. expected=[%s], actual=[%s]", expected.TenantID, actual.TenantID)
- }
- if expected.UserID != actual.UserID {
- t.Errorf("UserID differs. expected=[%s], actual=[%s]", expected.UserID, actual.UserID)
- }
- if expected.Name != actual.Name {
- t.Errorf("Name differs. expected=[%s], actual=[%s]", expected.Name, actual.Name)
- }
- if expected.Updated != actual.Updated {
- t.Errorf("Updated differs. expected=[%s], actual=[%s]", expected.Updated, actual.Updated)
- }
- if expected.Created != actual.Created {
- t.Errorf("Created differs. expected=[%s], actual=[%s]", expected.Created, actual.Created)
- }
- if expected.HostID != actual.HostID {
- t.Errorf("HostID differs. expected=[%s], actual=[%s]", expected.HostID, actual.HostID)
- }
- if expected.Status != actual.Status {
- t.Errorf("Status differs. expected=[%s], actual=[%s]", expected.Status, actual.Status)
- }
- if expected.Progress != actual.Progress {
- t.Errorf("Progress differs. expected=[%s], actual=[%s]", expected.Progress, actual.Progress)
- }
- if expected.AccessIPv4 != actual.AccessIPv4 {
- t.Errorf("AccessIPv4 differs. expected=[%s], actual=[%s]", expected.AccessIPv4, actual.AccessIPv4)
- }
- if expected.AccessIPv6 != actual.AccessIPv6 {
- t.Errorf("AccessIPv6 differs. expected=[%s], actual=[%s]", expected.AccessIPv6, actual.AccessIPv6)
- }
- if !reflect.DeepEqual(expected.Image, actual.Image) {
- t.Errorf("Image differs. expected=[%s], actual=[%s]", expected.Image, actual.Image)
- }
- if !reflect.DeepEqual(expected.Flavor, actual.Flavor) {
- t.Errorf("Flavor differs. expected=[%s], actual=[%s]", expected.Flavor, actual.Flavor)
- }
- if !reflect.DeepEqual(expected.Addresses, actual.Addresses) {
- t.Errorf("Addresses differ. expected=[%s], actual=[%s]", expected.Addresses, actual.Addresses)
- }
- if !reflect.DeepEqual(expected.Metadata, actual.Metadata) {
- t.Errorf("Metadata differs. expected=[%s], actual=[%s]", expected.Metadata, actual.Metadata)
- }
- if !reflect.DeepEqual(expected.Links, actual.Links) {
- t.Errorf("Links differs. expected=[%s], actual=[%s]", expected.Links, actual.Links)
- }
- if expected.KeyName != actual.KeyName {
- t.Errorf("KeyName differs. expected=[%s], actual=[%s]", expected.KeyName, actual.KeyName)
- }
- if expected.AdminPass != actual.AdminPass {
- t.Errorf("AdminPass differs. expected=[%s], actual=[%s]", expected.AdminPass, actual.AdminPass)
- }
-}