blob: 580f02a54fc3a1dcbd1cd5f14285ff8f11b2c19c [file] [log] [blame]
Jamie Hannaford05665d62015-10-07 14:01:50 +02001package configurations
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
7 "github.com/rackspace/gophercloud/pagination"
8 "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
9 th "github.com/rackspace/gophercloud/testhelper"
10 fake "github.com/rackspace/gophercloud/testhelper/client"
11 "github.com/rackspace/gophercloud/testhelper/fixture"
12)
13
14var (
15 configID = "{configID}"
16 _baseURL = "/configurations"
17 resURL = _baseURL + "/" + configID
18
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
26)
27
28func TestList(t *testing.T) {
29 th.SetupHTTP()
30 defer th.TeardownHTTP()
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +020031 fixture.SetupHandler(t, _baseURL, "GET", "", listConfigsJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +020032
33 count := 0
34 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
35 count++
36 actual, err := os.ExtractConfigs(page)
37 th.AssertNoErr(t, err)
38
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +020039 expected := []os.Config{exampleConfig}
Jamie Hannaford05665d62015-10-07 14:01:50 +020040 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 Hannafordb9aa87f2015-10-07 14:12:59 +020052 fixture.SetupHandler(t, resURL, "GET", "", getConfigJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +020053
54 config, err := Get(fake.ServiceClient(), configID).Extract()
55 th.AssertNoErr(t, err)
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +020056 th.AssertDeepEquals(t, &exampleConfig, config)
Jamie Hannaford05665d62015-10-07 14:01:50 +020057}
58
59func TestCreate(t *testing.T) {
60 th.SetupHTTP()
61 defer th.TeardownHTTP()
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +020062 fixture.SetupHandler(t, _baseURL, "POST", createReq, createConfigJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +020063
64 opts := os.CreateOpts{
65 Datastore: &os.DatastoreOpts{
66 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
77 config, err := Create(fake.ServiceClient(), opts).Extract()
78 th.AssertNoErr(t, err)
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +020079 th.AssertDeepEquals(t, &exampleConfigWithValues, config)
Jamie Hannaford05665d62015-10-07 14:01:50 +020080}
81
82func TestUpdate(t *testing.T) {
83 th.SetupHTTP()
84 defer th.TeardownHTTP()
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +020085 fixture.SetupHandler(t, resURL, "PATCH", updateReq, "", 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +020086
87 opts := os.UpdateOpts{
88 Values: map[string]interface{}{
89 "connect_timeout": 300,
90 },
91 }
92
93 err := Update(fake.ServiceClient(), configID, opts).ExtractErr()
94 th.AssertNoErr(t, err)
95}
96
97func TestReplace(t *testing.T) {
98 th.SetupHTTP()
99 defer th.TeardownHTTP()
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +0200100 fixture.SetupHandler(t, resURL, "PUT", updateReq, "", 202)
Jamie Hannaford05665d62015-10-07 14:01:50 +0200101
102 opts := os.UpdateOpts{
103 Values: map[string]interface{}{
104 "connect_timeout": 300,
105 },
106 }
107
108 err := Replace(fake.ServiceClient(), configID, opts).ExtractErr()
109 th.AssertNoErr(t, err)
110}
111
112func TestDelete(t *testing.T) {
113 th.SetupHTTP()
114 defer th.TeardownHTTP()
115 fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
116
117 err := Delete(fake.ServiceClient(), configID).ExtractErr()
118 th.AssertNoErr(t, err)
119}
120
121func TestListInstances(t *testing.T) {
122 th.SetupHTTP()
123 defer th.TeardownHTTP()
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +0200124 fixture.SetupHandler(t, resURL+"/instances", "GET", "", listInstancesJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +0200125
126 expectedInstance := instances.Instance{
127 ID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
128 Name: "json_rack_instance",
129 }
130
131 pages := 0
132 err := ListInstances(fake.ServiceClient(), configID).EachPage(func(page pagination.Page) (bool, error) {
133 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}
148
149func TestListDSParams(t *testing.T) {
150 th.SetupHTTP()
151 defer th.TeardownHTTP()
Jamie Hannafordb9aa87f2015-10-07 14:12:59 +0200152 fixture.SetupHandler(t, dsParamListURL, "GET", "", listParamsJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +0200153
154 pages := 0
155 err := ListDatastoreParams(fake.ServiceClient(), dsID, versionID).EachPage(func(page pagination.Page) (bool, error) {
156 pages++
157
158 actual, err := os.ExtractParams(page)
159 if err != nil {
160 return false, err
161 }
162
163 expected := []os.Param{
164 os.Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
165 os.Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
166 os.Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
167 os.Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
168 }
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 Hannafordb9aa87f2015-10-07 14:12:59 +0200182 fixture.SetupHandler(t, dsParamGetURL, "GET", "", getParamJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +0200183
184 param, err := GetDatastoreParam(fake.ServiceClient(), dsID, versionID, paramID).Extract()
185 th.AssertNoErr(t, err)
186
187 expected := &os.Param{
188 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 Hannafordb9aa87f2015-10-07 14:12:59 +0200197 fixture.SetupHandler(t, globalParamListURL, "GET", "", listParamsJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +0200198
199 pages := 0
200 err := ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
201 pages++
202
203 actual, err := os.ExtractParams(page)
204 if err != nil {
205 return false, err
206 }
207
208 expected := []os.Param{
209 os.Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
210 os.Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
211 os.Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
212 os.Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
213 }
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 Hannafordb9aa87f2015-10-07 14:12:59 +0200227 fixture.SetupHandler(t, globalParamGetURL, "GET", "", getParamJSON, 200)
Jamie Hannaford05665d62015-10-07 14:01:50 +0200228
229 param, err := GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract()
230 th.AssertNoErr(t, err)
231
232 expected := &os.Param{
233 Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
234 }
235
236 th.AssertDeepEquals(t, expected, param)
237}