blob: eb1da6aed9a73017662e131014c16ce803c4be5f [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaford9fdda582015-02-10 12:15:43 +01003package instances
4
5import (
6 "fmt"
Jamie Hannaford4a170282015-02-18 14:16:57 +01007 "testing"
Jamie Hannaforde65ad952015-11-16 14:05:11 +01008 "time"
Jamie Hannaford9fdda582015-02-10 12:15:43 +01009
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010010 "github.com/rackspace/gophercloud"
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020011 "github.com/rackspace/gophercloud/openstack/db/v1/datastores"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010012 "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
Jamie Hannaford4a170282015-02-18 14:16:57 +010013 "github.com/rackspace/gophercloud/testhelper/fixture"
Jamie Hannaford9fdda582015-02-10 12:15:43 +010014)
15
Jamie Hannaforde65ad952015-11-16 14:05:11 +010016var (
17 timestamp = "2015-11-12T14:22:42Z"
18 timeVal, _ = time.Parse(time.RFC3339, timestamp)
19)
20
21var instance = `
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010022{
Jamie Hannaforde65ad952015-11-16 14:05:11 +010023 "created": "` + timestamp + `",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010024 "datastore": {
25 "type": "mysql",
26 "version": "5.6"
27 },
28 "flavor": {
29 "id": "1",
30 "links": [
31 {
32 "href": "https://my-openstack.com/v1.0/1234/flavors/1",
33 "rel": "self"
34 },
35 {
36 "href": "https://my-openstack.com/v1.0/1234/flavors/1",
37 "rel": "bookmark"
38 }
39 ]
40 },
41 "links": [
42 {
43 "href": "https://my-openstack.com/v1.0/1234/instances/1",
44 "rel": "self"
45 }
46 ],
47 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
48 "id": "{instanceID}",
49 "name": "json_rack_instance",
50 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +010051 "updated": "` + timestamp + `",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010052 "volume": {
53 "size": 2
54 }
55}
56`
57
58var createReq = `
Jamie Hannaford821015f2015-02-10 12:58:36 +010059{
60 "instance": {
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010061 "databases": [
Jamie Hannaford821015f2015-02-10 12:58:36 +010062 {
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010063 "character_set": "utf8",
64 "collate": "utf8_general_ci",
65 "name": "sampledb"
66 },
67 {
68 "name": "nextround"
Jamie Hannaford821015f2015-02-10 12:58:36 +010069 }
70 ],
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010071 "flavorRef": "1",
Jamie Hannaford821015f2015-02-10 12:58:36 +010072 "name": "json_rack_instance",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010073 "users": [
74 {
75 "databases": [
76 {
77 "name": "sampledb"
78 }
79 ],
80 "name": "demouser",
81 "password": "demopassword"
82 }
83 ],
Jamie Hannaford821015f2015-02-10 12:58:36 +010084 "volume": {
85 "size": 2
86 }
87 }
88}
89`
90
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010091var (
Jamie Hannaford4a170282015-02-18 14:16:57 +010092 instanceID = "{instanceID}"
93 rootURL = "/instances"
94 resURL = rootURL + "/" + instanceID
95 uRootURL = resURL + "/root"
96 aURL = resURL + "/action"
97)
98
99var (
Jamie Hannafordd2b755f2015-10-07 14:01:57 +0200100 restartReq = `{"restart": {}}`
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100101 resizeReq = `{"resize": {"flavorRef": "2"}}`
102 resizeVolReq = `{"resize": {"volume": {"size": 4}}}`
103)
Jamie Hannaford9fdda582015-02-10 12:15:43 +0100104
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100105var (
106 createResp = fmt.Sprintf(`{"instance": %s}`, instance)
107 listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
108 getInstanceResp = createResp
109 enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}`
110 isUserEnabledResp = `{"rootEnabled":true}`
111)
Jamie Hannaford9fdda582015-02-10 12:15:43 +0100112
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100113var expectedInstance = Instance{
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100114 Created: timeVal,
115 Updated: timeVal,
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100116 Flavor: flavors.Flavor{
Jamie Hannaford11108402015-02-23 10:31:41 +0100117 ID: "1",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100118 Links: []gophercloud.Link{
119 gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "self"},
120 gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "bookmark"},
121 },
122 },
123 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
124 ID: instanceID,
125 Links: []gophercloud.Link{
126 gophercloud.Link{Href: "https://my-openstack.com/v1.0/1234/instances/1", Rel: "self"},
127 },
128 Name: "json_rack_instance",
129 Status: "BUILD",
130 Volume: Volume{Size: 2},
Jamie Hannaford52dbcee2015-10-06 16:09:56 +0200131 Datastore: datastores.DatastorePartial{
132 Type: "mysql",
133 Version: "5.6",
134 },
Jamie Hannaford219ca592015-02-10 15:59:05 +0100135}
Jamie Hannaford4a170282015-02-18 14:16:57 +0100136
137func HandleCreate(t *testing.T) {
138 fixture.SetupHandler(t, rootURL, "POST", createReq, createResp, 200)
139}
140
141func HandleList(t *testing.T) {
142 fixture.SetupHandler(t, rootURL, "GET", "", listInstancesResp, 200)
143}
144
145func HandleGet(t *testing.T) {
146 fixture.SetupHandler(t, resURL, "GET", "", getInstanceResp, 200)
147}
148
149func HandleDelete(t *testing.T) {
150 fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
151}
152
153func HandleEnableRoot(t *testing.T) {
154 fixture.SetupHandler(t, uRootURL, "POST", "", enableUserResp, 200)
155}
156
157func HandleIsRootEnabled(t *testing.T) {
158 fixture.SetupHandler(t, uRootURL, "GET", "", isUserEnabledResp, 200)
159}
160
161func HandleRestart(t *testing.T) {
162 fixture.SetupHandler(t, aURL, "POST", restartReq, "", 202)
163}
164
165func HandleResize(t *testing.T) {
166 fixture.SetupHandler(t, aURL, "POST", resizeReq, "", 202)
167}
168
169func HandleResizeVol(t *testing.T) {
170 fixture.SetupHandler(t, aURL, "POST", resizeVolReq, "", 202)
171}