blob: e0a0d28d76ebfe76a7bf8c872d059d09bd362a65 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Jamie Hannaford9fdda582015-02-10 12:15:43 +01002
3import (
4 "fmt"
Jamie Hannaford4a170282015-02-18 14:16:57 +01005 "testing"
Jamie Hannaforde65ad952015-11-16 14:05:11 +01006 "time"
Jamie Hannaford9fdda582015-02-10 12:15:43 +01007
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud"
9 "github.com/gophercloud/gophercloud/openstack/db/v1/datastores"
10 "github.com/gophercloud/gophercloud/openstack/db/v1/flavors"
jrperritt3d966162016-06-06 14:08:54 -050011 "github.com/gophercloud/gophercloud/openstack/db/v1/instances"
Jon Perritt27249f42016-02-18 10:35:59 -060012 "github.com/gophercloud/gophercloud/testhelper/fixture"
Jamie Hannaford9fdda582015-02-10 12:15:43 +010013)
14
Jamie Hannaforde65ad952015-11-16 14:05:11 +010015var (
16 timestamp = "2015-11-12T14:22:42Z"
17 timeVal, _ = time.Parse(time.RFC3339, timestamp)
18)
19
20var instance = `
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010021{
Jamie Hannaforde65ad952015-11-16 14:05:11 +010022 "created": "` + timestamp + `",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010023 "datastore": {
24 "type": "mysql",
25 "version": "5.6"
26 },
27 "flavor": {
Jon Perritt12395212016-02-24 10:41:17 -060028 "id": 1,
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010029 "links": [
30 {
31 "href": "https://my-openstack.com/v1.0/1234/flavors/1",
32 "rel": "self"
33 },
34 {
35 "href": "https://my-openstack.com/v1.0/1234/flavors/1",
36 "rel": "bookmark"
37 }
38 ]
39 },
40 "links": [
41 {
42 "href": "https://my-openstack.com/v1.0/1234/instances/1",
43 "rel": "self"
44 }
45 ],
46 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
47 "id": "{instanceID}",
48 "name": "json_rack_instance",
49 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +010050 "updated": "` + timestamp + `",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010051 "volume": {
52 "size": 2
53 }
54}
55`
56
57var createReq = `
Jamie Hannaford821015f2015-02-10 12:58:36 +010058{
59 "instance": {
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010060 "databases": [
Jamie Hannaford821015f2015-02-10 12:58:36 +010061 {
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010062 "character_set": "utf8",
63 "collate": "utf8_general_ci",
64 "name": "sampledb"
65 },
66 {
67 "name": "nextround"
Jamie Hannaford821015f2015-02-10 12:58:36 +010068 }
69 ],
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010070 "flavorRef": "1",
Jamie Hannaford821015f2015-02-10 12:58:36 +010071 "name": "json_rack_instance",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010072 "users": [
73 {
74 "databases": [
75 {
76 "name": "sampledb"
77 }
78 ],
79 "name": "demouser",
80 "password": "demopassword"
81 }
82 ],
Jamie Hannaford821015f2015-02-10 12:58:36 +010083 "volume": {
84 "size": 2
85 }
86 }
87}
88`
89
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010090var (
Jamie Hannaford4a170282015-02-18 14:16:57 +010091 instanceID = "{instanceID}"
92 rootURL = "/instances"
93 resURL = rootURL + "/" + instanceID
94 uRootURL = resURL + "/root"
95 aURL = resURL + "/action"
96)
97
98var (
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020099 restartReq = `{"restart": {}}`
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100100 resizeReq = `{"resize": {"flavorRef": "2"}}`
101 resizeVolReq = `{"resize": {"volume": {"size": 4}}}`
102)
Jamie Hannaford9fdda582015-02-10 12:15:43 +0100103
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100104var (
105 createResp = fmt.Sprintf(`{"instance": %s}`, instance)
106 listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
107 getInstanceResp = createResp
108 enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}`
109 isUserEnabledResp = `{"rootEnabled":true}`
110)
Jamie Hannaford9fdda582015-02-10 12:15:43 +0100111
jrperritt3d966162016-06-06 14:08:54 -0500112var expectedInstance = instances.Instance{
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100113 Created: timeVal,
114 Updated: timeVal,
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100115 Flavor: flavors.Flavor{
Jon Perritt12395212016-02-24 10:41:17 -0600116 ID: 1,
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100117 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500118 {Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "self"},
119 {Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "bookmark"},
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100120 },
121 },
122 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
123 ID: instanceID,
124 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500125 {Href: "https://my-openstack.com/v1.0/1234/instances/1", Rel: "self"},
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100126 },
127 Name: "json_rack_instance",
128 Status: "BUILD",
jrperritt3d966162016-06-06 14:08:54 -0500129 Volume: instances.Volume{Size: 2},
Jamie Hannaford52dbcee2015-10-06 16:09:56 +0200130 Datastore: datastores.DatastorePartial{
131 Type: "mysql",
132 Version: "5.6",
133 },
Jamie Hannaford219ca592015-02-10 15:59:05 +0100134}
Jamie Hannaford4a170282015-02-18 14:16:57 +0100135
136func HandleCreate(t *testing.T) {
137 fixture.SetupHandler(t, rootURL, "POST", createReq, createResp, 200)
138}
139
140func HandleList(t *testing.T) {
141 fixture.SetupHandler(t, rootURL, "GET", "", listInstancesResp, 200)
142}
143
144func HandleGet(t *testing.T) {
145 fixture.SetupHandler(t, resURL, "GET", "", getInstanceResp, 200)
146}
147
148func HandleDelete(t *testing.T) {
149 fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
150}
151
152func HandleEnableRoot(t *testing.T) {
153 fixture.SetupHandler(t, uRootURL, "POST", "", enableUserResp, 200)
154}
155
156func HandleIsRootEnabled(t *testing.T) {
157 fixture.SetupHandler(t, uRootURL, "GET", "", isUserEnabledResp, 200)
158}
159
160func HandleRestart(t *testing.T) {
161 fixture.SetupHandler(t, aURL, "POST", restartReq, "", 202)
162}
163
164func HandleResize(t *testing.T) {
165 fixture.SetupHandler(t, aURL, "POST", resizeReq, "", 202)
166}
167
168func HandleResizeVol(t *testing.T) {
169 fixture.SetupHandler(t, aURL, "POST", resizeVolReq, "", 202)
170}