blob: 643f3634264b88febd6300bdfb6f5f296c93f774 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Jamie Hannaforded7f4532015-02-17 14:56:30 +01002
3import (
4 "testing"
5
jrperritt3d966162016-06-06 14:08:54 -05006 "github.com/gophercloud/gophercloud/openstack/db/v1/configurations"
Jon Perrittc2697cf2016-02-18 12:46:37 -06007 "github.com/gophercloud/gophercloud/openstack/db/v1/instances"
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud/pagination"
Jon Perritt27249f42016-02-18 10:35:59 -06009 th "github.com/gophercloud/gophercloud/testhelper"
10 fake "github.com/gophercloud/gophercloud/testhelper/client"
11 "github.com/gophercloud/gophercloud/testhelper/fixture"
Jamie Hannaforded7f4532015-02-17 14:56:30 +010012)
13
14var (
15 configID = "{configID}"
16 _baseURL = "/configurations"
17 resURL = _baseURL + "/" + configID
Jamie Hannaford23867bb2015-02-17 15:56:48 +010018
19 dsID = "{datastoreID}"
20 versionID = "{versionID}"
21 paramID = "{paramID}"
22 dsParamListURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters"
23 dsParamGetURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters/" + paramID
24 globalParamListURL = "/datastores/versions/" + versionID + "/parameters"
25 globalParamGetURL = "/datastores/versions/" + versionID + "/parameters/" + paramID
Jamie Hannaforded7f4532015-02-17 14:56:30 +010026)
27
28func TestList(t *testing.T) {
29 th.SetupHTTP()
30 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +020031 fixture.SetupHandler(t, _baseURL, "GET", "", ListConfigsJSON, 200)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010032
33 count := 0
jrperritt3d966162016-06-06 14:08:54 -050034 err := configurations.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaforded7f4532015-02-17 14:56:30 +010035 count++
jrperritt3d966162016-06-06 14:08:54 -050036 actual, err := configurations.ExtractConfigs(page)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010037 th.AssertNoErr(t, err)
38
jrperritt3d966162016-06-06 14:08:54 -050039 expected := []configurations.Config{ExampleConfig}
Jamie Hannaforded7f4532015-02-17 14:56:30 +010040 th.AssertDeepEquals(t, expected, actual)
41
42 return true, nil
43 })
44
45 th.AssertEquals(t, 1, count)
46 th.AssertNoErr(t, err)
47}
48
49func TestGet(t *testing.T) {
50 th.SetupHTTP()
51 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +020052 fixture.SetupHandler(t, resURL, "GET", "", GetConfigJSON, 200)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010053
jrperritt3d966162016-06-06 14:08:54 -050054 config, err := configurations.Get(fake.ServiceClient(), configID).Extract()
Jamie Hannaforded7f4532015-02-17 14:56:30 +010055 th.AssertNoErr(t, err)
Jamie Hannafordd87c7d62015-10-07 14:20:13 +020056 th.AssertDeepEquals(t, &ExampleConfig, config)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010057}
58
59func TestCreate(t *testing.T) {
60 th.SetupHTTP()
61 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +020062 fixture.SetupHandler(t, _baseURL, "POST", CreateReq, CreateConfigJSON, 200)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010063
jrperritt3d966162016-06-06 14:08:54 -050064 opts := configurations.CreateOpts{
65 Datastore: &configurations.DatastoreOpts{
Jamie Hannaforded7f4532015-02-17 14:56:30 +010066 Type: "a00000a0-00a0-0a00-00a0-000a000000aa",
67 Version: "b00000b0-00b0-0b00-00b0-000b000000bb",
68 },
69 Description: "example description",
70 Name: "example-configuration-name",
71 Values: map[string]interface{}{
72 "collation_server": "latin1_swedish_ci",
73 "connect_timeout": 120,
74 },
75 }
76
jrperritt3d966162016-06-06 14:08:54 -050077 config, err := configurations.Create(fake.ServiceClient(), opts).Extract()
Jamie Hannaforded7f4532015-02-17 14:56:30 +010078 th.AssertNoErr(t, err)
Jamie Hannafordd87c7d62015-10-07 14:20:13 +020079 th.AssertDeepEquals(t, &ExampleConfigWithValues, config)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010080}
81
82func TestUpdate(t *testing.T) {
83 th.SetupHTTP()
84 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +020085 fixture.SetupHandler(t, resURL, "PATCH", UpdateReq, "", 200)
Jamie Hannaforded7f4532015-02-17 14:56:30 +010086
jrperritt3d966162016-06-06 14:08:54 -050087 opts := configurations.UpdateOpts{
Jamie Hannaforded7f4532015-02-17 14:56:30 +010088 Values: map[string]interface{}{
89 "connect_timeout": 300,
90 },
91 }
92
jrperritt3d966162016-06-06 14:08:54 -050093 err := configurations.Update(fake.ServiceClient(), configID, opts).ExtractErr()
Jamie Hannaforded7f4532015-02-17 14:56:30 +010094 th.AssertNoErr(t, err)
95}
96
97func TestReplace(t *testing.T) {
98 th.SetupHTTP()
99 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +0200100 fixture.SetupHandler(t, resURL, "PUT", UpdateReq, "", 202)
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100101
jrperritt3d966162016-06-06 14:08:54 -0500102 opts := configurations.UpdateOpts{
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100103 Values: map[string]interface{}{
104 "connect_timeout": 300,
105 },
106 }
107
jrperritt3d966162016-06-06 14:08:54 -0500108 err := configurations.Replace(fake.ServiceClient(), configID, opts).ExtractErr()
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100109 th.AssertNoErr(t, err)
110}
111
112func TestDelete(t *testing.T) {
113 th.SetupHTTP()
114 defer th.TeardownHTTP()
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100115 fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
116
jrperritt3d966162016-06-06 14:08:54 -0500117 err := configurations.Delete(fake.ServiceClient(), configID).ExtractErr()
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100118 th.AssertNoErr(t, err)
119}
120
121func TestListInstances(t *testing.T) {
122 th.SetupHTTP()
123 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +0200124 fixture.SetupHandler(t, resURL+"/instances", "GET", "", ListInstancesJSON, 200)
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100125
126 expectedInstance := instances.Instance{
127 ID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
128 Name: "json_rack_instance",
129 }
130
131 pages := 0
jrperritt3d966162016-06-06 14:08:54 -0500132 err := configurations.ListInstances(fake.ServiceClient(), configID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaforded7f4532015-02-17 14:56:30 +0100133 pages++
134
135 actual, err := instances.ExtractInstances(page)
136 if err != nil {
137 return false, err
138 }
139
140 th.AssertDeepEquals(t, actual, []instances.Instance{expectedInstance})
141
142 return true, nil
143 })
144
145 th.AssertNoErr(t, err)
146 th.AssertEquals(t, 1, pages)
147}
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100148
149func TestListDSParams(t *testing.T) {
150 th.SetupHTTP()
151 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +0200152 fixture.SetupHandler(t, dsParamListURL, "GET", "", ListParamsJSON, 200)
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100153
154 pages := 0
jrperritt3d966162016-06-06 14:08:54 -0500155 err := configurations.ListDatastoreParams(fake.ServiceClient(), dsID, versionID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100156 pages++
157
jrperritt3d966162016-06-06 14:08:54 -0500158 actual, err := configurations.ExtractParams(page)
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100159 if err != nil {
160 return false, err
161 }
162
jrperritt3d966162016-06-06 14:08:54 -0500163 expected := []configurations.Param{
164 {Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
165 {Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
166 {Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
167 {Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100168 }
169
170 th.AssertDeepEquals(t, actual, expected)
171
172 return true, nil
173 })
174
175 th.AssertNoErr(t, err)
176 th.AssertEquals(t, 1, pages)
177}
178
179func TestGetDSParam(t *testing.T) {
180 th.SetupHTTP()
181 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +0200182 fixture.SetupHandler(t, dsParamGetURL, "GET", "", GetParamJSON, 200)
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100183
jrperritt3d966162016-06-06 14:08:54 -0500184 param, err := configurations.GetDatastoreParam(fake.ServiceClient(), dsID, versionID, paramID).Extract()
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100185 th.AssertNoErr(t, err)
186
jrperritt3d966162016-06-06 14:08:54 -0500187 expected := &configurations.Param{
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100188 Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
189 }
190
191 th.AssertDeepEquals(t, expected, param)
192}
193
194func TestListGlobalParams(t *testing.T) {
195 th.SetupHTTP()
196 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +0200197 fixture.SetupHandler(t, globalParamListURL, "GET", "", ListParamsJSON, 200)
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100198
199 pages := 0
jrperritt3d966162016-06-06 14:08:54 -0500200 err := configurations.ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100201 pages++
202
jrperritt3d966162016-06-06 14:08:54 -0500203 actual, err := configurations.ExtractParams(page)
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100204 if err != nil {
205 return false, err
206 }
207
jrperritt3d966162016-06-06 14:08:54 -0500208 expected := []configurations.Param{
209 {Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
210 {Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
211 {Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
212 {Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100213 }
214
215 th.AssertDeepEquals(t, actual, expected)
216
217 return true, nil
218 })
219
220 th.AssertNoErr(t, err)
221 th.AssertEquals(t, 1, pages)
222}
223
224func TestGetGlobalParam(t *testing.T) {
225 th.SetupHTTP()
226 defer th.TeardownHTTP()
Jamie Hannafordd87c7d62015-10-07 14:20:13 +0200227 fixture.SetupHandler(t, globalParamGetURL, "GET", "", GetParamJSON, 200)
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100228
jrperritt3d966162016-06-06 14:08:54 -0500229 param, err := configurations.GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract()
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100230 th.AssertNoErr(t, err)
231
jrperritt3d966162016-06-06 14:08:54 -0500232 expected := &configurations.Param{
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100233 Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
234 }
235
236 th.AssertDeepEquals(t, expected, param)
237}