blob: 9347ee15be28f7962fbc93d9292aa6e732c9dc18 [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"
jrperritt3d966162016-06-06 14:08:54 -050010 "github.com/gophercloud/gophercloud/openstack/db/v1/instances"
Jon Perritt27249f42016-02-18 10:35:59 -060011 "github.com/gophercloud/gophercloud/testhelper/fixture"
Jamie Hannaford9fdda582015-02-10 12:15:43 +010012)
13
Jamie Hannaforde65ad952015-11-16 14:05:11 +010014var (
esalipe58d15022017-01-13 19:31:08 +020015 timestamp = "2015-11-12T14:22:42"
16 timeVal, _ = time.Parse(gophercloud.RFC3339NoZ, timestamp)
Jamie Hannaforde65ad952015-11-16 14:05:11 +010017)
18
19var instance = `
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010020{
Jamie Hannaforde65ad952015-11-16 14:05:11 +010021 "created": "` + timestamp + `",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010022 "datastore": {
23 "type": "mysql",
24 "version": "5.6"
25 },
26 "flavor": {
esalipef7b8b062017-01-19 02:08:59 +020027 "id": "1",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010028 "links": [
29 {
Monty Taylor9a5595b2017-03-13 13:04:29 -050030 "href": "https://openstack.example.com/v1.0/1234/flavors/1",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010031 "rel": "self"
32 },
33 {
Monty Taylor9a5595b2017-03-13 13:04:29 -050034 "href": "https://openstack.example.com/v1.0/1234/flavors/1",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010035 "rel": "bookmark"
36 }
37 ]
38 },
39 "links": [
40 {
Monty Taylor9a5595b2017-03-13 13:04:29 -050041 "href": "https://openstack.example.com/v1.0/1234/instances/1",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010042 "rel": "self"
43 }
44 ],
Monty Taylor9a5595b2017-03-13 13:04:29 -050045 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.openstack.example.com",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010046 "id": "{instanceID}",
47 "name": "json_rack_instance",
48 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +010049 "updated": "` + timestamp + `",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010050 "volume": {
51 "size": 2
52 }
53}
54`
55
56var createReq = `
Jamie Hannaford821015f2015-02-10 12:58:36 +010057{
58 "instance": {
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010059 "databases": [
Jamie Hannaford821015f2015-02-10 12:58:36 +010060 {
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010061 "character_set": "utf8",
62 "collate": "utf8_general_ci",
63 "name": "sampledb"
64 },
65 {
66 "name": "nextround"
Jamie Hannaford821015f2015-02-10 12:58:36 +010067 }
68 ],
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010069 "flavorRef": "1",
Jamie Hannaford821015f2015-02-10 12:58:36 +010070 "name": "json_rack_instance",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010071 "users": [
72 {
73 "databases": [
74 {
75 "name": "sampledb"
76 }
77 ],
78 "name": "demouser",
79 "password": "demopassword"
80 }
81 ],
Jamie Hannaford821015f2015-02-10 12:58:36 +010082 "volume": {
83 "size": 2
84 }
85 }
86}
87`
88
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010089var (
Jamie Hannaford4a170282015-02-18 14:16:57 +010090 instanceID = "{instanceID}"
91 rootURL = "/instances"
92 resURL = rootURL + "/" + instanceID
93 uRootURL = resURL + "/root"
94 aURL = resURL + "/action"
95)
96
97var (
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020098 restartReq = `{"restart": {}}`
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010099 resizeReq = `{"resize": {"flavorRef": "2"}}`
100 resizeVolReq = `{"resize": {"volume": {"size": 4}}}`
101)
Jamie Hannaford9fdda582015-02-10 12:15:43 +0100102
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100103var (
104 createResp = fmt.Sprintf(`{"instance": %s}`, instance)
105 listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
106 getInstanceResp = createResp
107 enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}`
108 isUserEnabledResp = `{"rootEnabled":true}`
109)
Jamie Hannaford9fdda582015-02-10 12:15:43 +0100110
jrperritt3d966162016-06-06 14:08:54 -0500111var expectedInstance = instances.Instance{
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100112 Created: timeVal,
113 Updated: timeVal,
esalipef7b8b062017-01-19 02:08:59 +0200114 Flavor: instances.Flavor{
115 ID: "1",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100116 Links: []gophercloud.Link{
Monty Taylor9a5595b2017-03-13 13:04:29 -0500117 {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
118 {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "bookmark"},
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100119 },
120 },
Monty Taylor9a5595b2017-03-13 13:04:29 -0500121 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.openstack.example.com",
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100122 ID: instanceID,
123 Links: []gophercloud.Link{
Monty Taylor9a5595b2017-03-13 13:04:29 -0500124 {Href: "https://openstack.example.com/v1.0/1234/instances/1", Rel: "self"},
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +0100125 },
126 Name: "json_rack_instance",
127 Status: "BUILD",
jrperritt3d966162016-06-06 14:08:54 -0500128 Volume: instances.Volume{Size: 2},
Jamie Hannaford52dbcee2015-10-06 16:09:56 +0200129 Datastore: datastores.DatastorePartial{
130 Type: "mysql",
131 Version: "5.6",
132 },
Jamie Hannaford219ca592015-02-10 15:59:05 +0100133}
Jamie Hannaford4a170282015-02-18 14:16:57 +0100134
135func HandleCreate(t *testing.T) {
136 fixture.SetupHandler(t, rootURL, "POST", createReq, createResp, 200)
137}
138
139func HandleList(t *testing.T) {
140 fixture.SetupHandler(t, rootURL, "GET", "", listInstancesResp, 200)
141}
142
143func HandleGet(t *testing.T) {
144 fixture.SetupHandler(t, resURL, "GET", "", getInstanceResp, 200)
145}
146
147func HandleDelete(t *testing.T) {
148 fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
149}
150
151func HandleEnableRoot(t *testing.T) {
152 fixture.SetupHandler(t, uRootURL, "POST", "", enableUserResp, 200)
153}
154
155func HandleIsRootEnabled(t *testing.T) {
156 fixture.SetupHandler(t, uRootURL, "GET", "", isUserEnabledResp, 200)
157}
158
159func HandleRestart(t *testing.T) {
160 fixture.SetupHandler(t, aURL, "POST", restartReq, "", 202)
161}
162
163func HandleResize(t *testing.T) {
164 fixture.SetupHandler(t, aURL, "POST", resizeReq, "", 202)
165}
166
167func HandleResizeVol(t *testing.T) {
168 fixture.SetupHandler(t, aURL, "POST", resizeVolReq, "", 202)
169}