Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit b9aa87f

Browse files
author
Jamie Hannaford
committed
test fixes
1 parent d2b755f commit b9aa87f

File tree

2 files changed

+166
-13
lines changed

2 files changed

+166
-13
lines changed

rackspace/db/v1/configurations/delegate_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ var (
2828
func TestList(t *testing.T) {
2929
th.SetupHTTP()
3030
defer th.TeardownHTTP()
31-
fixture.SetupHandler(t, _baseURL, "GET", "", os.ListConfigsJSON, 200)
31+
fixture.SetupHandler(t, _baseURL, "GET", "", listConfigsJSON, 200)
3232

3333
count := 0
3434
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
3535
count++
3636
actual, err := os.ExtractConfigs(page)
3737
th.AssertNoErr(t, err)
3838

39-
expected := []os.Config{os.ExampleConfig}
39+
expected := []os.Config{exampleConfig}
4040
th.AssertDeepEquals(t, expected, actual)
4141

4242
return true, nil
@@ -49,17 +49,17 @@ func TestList(t *testing.T) {
4949
func TestGet(t *testing.T) {
5050
th.SetupHTTP()
5151
defer th.TeardownHTTP()
52-
fixture.SetupHandler(t, resURL, "GET", "", os.GetConfigJSON, 200)
52+
fixture.SetupHandler(t, resURL, "GET", "", getConfigJSON, 200)
5353

5454
config, err := Get(fake.ServiceClient(), configID).Extract()
5555
th.AssertNoErr(t, err)
56-
th.AssertDeepEquals(t, &os.ExampleConfig, config)
56+
th.AssertDeepEquals(t, &exampleConfig, config)
5757
}
5858

5959
func TestCreate(t *testing.T) {
6060
th.SetupHTTP()
6161
defer th.TeardownHTTP()
62-
fixture.SetupHandler(t, _baseURL, "POST", os.CreateReq, os.CreateConfigJSON, 200)
62+
fixture.SetupHandler(t, _baseURL, "POST", createReq, createConfigJSON, 200)
6363

6464
opts := os.CreateOpts{
6565
Datastore: &os.DatastoreOpts{
@@ -76,13 +76,13 @@ func TestCreate(t *testing.T) {
7676

7777
config, err := Create(fake.ServiceClient(), opts).Extract()
7878
th.AssertNoErr(t, err)
79-
th.AssertDeepEquals(t, &os.ExampleConfigWithValues, config)
79+
th.AssertDeepEquals(t, &exampleConfigWithValues, config)
8080
}
8181

8282
func TestUpdate(t *testing.T) {
8383
th.SetupHTTP()
8484
defer th.TeardownHTTP()
85-
fixture.SetupHandler(t, resURL, "PATCH", os.UpdateReq, "", 200)
85+
fixture.SetupHandler(t, resURL, "PATCH", updateReq, "", 200)
8686

8787
opts := os.UpdateOpts{
8888
Values: map[string]interface{}{
@@ -97,7 +97,7 @@ func TestUpdate(t *testing.T) {
9797
func TestReplace(t *testing.T) {
9898
th.SetupHTTP()
9999
defer th.TeardownHTTP()
100-
fixture.SetupHandler(t, resURL, "PUT", os.UpdateReq, "", 202)
100+
fixture.SetupHandler(t, resURL, "PUT", updateReq, "", 202)
101101

102102
opts := os.UpdateOpts{
103103
Values: map[string]interface{}{
@@ -121,7 +121,7 @@ func TestDelete(t *testing.T) {
121121
func TestListInstances(t *testing.T) {
122122
th.SetupHTTP()
123123
defer th.TeardownHTTP()
124-
fixture.SetupHandler(t, resURL+"/instances", "GET", "", os.ListInstancesJSON, 200)
124+
fixture.SetupHandler(t, resURL+"/instances", "GET", "", listInstancesJSON, 200)
125125

126126
expectedInstance := instances.Instance{
127127
ID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
@@ -149,7 +149,7 @@ func TestListInstances(t *testing.T) {
149149
func TestListDSParams(t *testing.T) {
150150
th.SetupHTTP()
151151
defer th.TeardownHTTP()
152-
fixture.SetupHandler(t, dsParamListURL, "GET", "", os.ListParamsJSON, 200)
152+
fixture.SetupHandler(t, dsParamListURL, "GET", "", listParamsJSON, 200)
153153

154154
pages := 0
155155
err := ListDatastoreParams(fake.ServiceClient(), dsID, versionID).EachPage(func(page pagination.Page) (bool, error) {
@@ -179,7 +179,7 @@ func TestListDSParams(t *testing.T) {
179179
func TestGetDSParam(t *testing.T) {
180180
th.SetupHTTP()
181181
defer th.TeardownHTTP()
182-
fixture.SetupHandler(t, dsParamGetURL, "GET", "", os.GetParamJSON, 200)
182+
fixture.SetupHandler(t, dsParamGetURL, "GET", "", getParamJSON, 200)
183183

184184
param, err := GetDatastoreParam(fake.ServiceClient(), dsID, versionID, paramID).Extract()
185185
th.AssertNoErr(t, err)
@@ -194,7 +194,7 @@ func TestGetDSParam(t *testing.T) {
194194
func TestListGlobalParams(t *testing.T) {
195195
th.SetupHTTP()
196196
defer th.TeardownHTTP()
197-
fixture.SetupHandler(t, globalParamListURL, "GET", "", os.ListParamsJSON, 200)
197+
fixture.SetupHandler(t, globalParamListURL, "GET", "", listParamsJSON, 200)
198198

199199
pages := 0
200200
err := ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
@@ -224,7 +224,7 @@ func TestListGlobalParams(t *testing.T) {
224224
func TestGetGlobalParam(t *testing.T) {
225225
th.SetupHTTP()
226226
defer th.TeardownHTTP()
227-
fixture.SetupHandler(t, globalParamGetURL, "GET", "", os.GetParamJSON, 200)
227+
fixture.SetupHandler(t, globalParamGetURL, "GET", "", getParamJSON, 200)
228228

229229
param, err := GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract()
230230
th.AssertNoErr(t, err)
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package configurations
2+
3+
import (
4+
"fmt"
5+
6+
os "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
7+
)
8+
9+
const singleConfigJSON = `
10+
{
11+
"created": "2014-07-31T18:56:09",
12+
"datastore_name": "mysql",
13+
"datastore_version_id": "b00000b0-00b0-0b00-00b0-000b000000bb",
14+
"datastore_version_name": "5.6",
15+
"description": "example_description",
16+
"id": "005a8bb7-a8df-40ee-b0b7-fc144641abc2",
17+
"name": "example-configuration-name",
18+
"updated": "2014-07-31T18:56:09"
19+
}
20+
`
21+
22+
const singleConfigWithValuesJSON = `
23+
{
24+
"created": "2014-07-31T15:02:52",
25+
"datastore_name": "mysql",
26+
"datastore_version_id": "b00000b0-00b0-0b00-00b0-000b000000bb",
27+
"datastore_version_name": "5.6",
28+
"description": "example description",
29+
"id": "005a8bb7-a8df-40ee-b0b7-fc144641abc2",
30+
"instance_count": 0,
31+
"name": "example-configuration-name",
32+
"updated": "2014-07-31T15:02:52",
33+
"values": {
34+
"collation_server": "latin1_swedish_ci",
35+
"connect_timeout": 120
36+
}
37+
}
38+
`
39+
40+
var (
41+
listConfigsJSON = fmt.Sprintf(`{"configurations": [%s]}`, singleConfigJSON)
42+
getConfigJSON = fmt.Sprintf(`{"configuration": %s}`, singleConfigJSON)
43+
createConfigJSON = fmt.Sprintf(`{"configuration": %s}`, singleConfigWithValuesJSON)
44+
)
45+
46+
var createReq = `
47+
{
48+
"configuration": {
49+
"datastore": {
50+
"type": "a00000a0-00a0-0a00-00a0-000a000000aa",
51+
"version": "b00000b0-00b0-0b00-00b0-000b000000bb"
52+
},
53+
"description": "example description",
54+
"name": "example-configuration-name",
55+
"values": {
56+
"collation_server": "latin1_swedish_ci",
57+
"connect_timeout": 120
58+
}
59+
}
60+
}
61+
`
62+
63+
var updateReq = `
64+
{
65+
"configuration": {
66+
"values": {
67+
"connect_timeout": 300
68+
}
69+
}
70+
}
71+
`
72+
73+
var listInstancesJSON = `
74+
{
75+
"instances": [
76+
{
77+
"id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
78+
"name": "json_rack_instance"
79+
}
80+
]
81+
}
82+
`
83+
84+
var listParamsJSON = `
85+
{
86+
"configuration-parameters": [
87+
{
88+
"max": 1,
89+
"min": 0,
90+
"name": "innodb_file_per_table",
91+
"restart_required": true,
92+
"type": "integer"
93+
},
94+
{
95+
"max": 4294967296,
96+
"min": 0,
97+
"name": "key_buffer_size",
98+
"restart_required": false,
99+
"type": "integer"
100+
},
101+
{
102+
"max": 65535,
103+
"min": 2,
104+
"name": "connect_timeout",
105+
"restart_required": false,
106+
"type": "integer"
107+
},
108+
{
109+
"max": 4294967296,
110+
"min": 0,
111+
"name": "join_buffer_size",
112+
"restart_required": false,
113+
"type": "integer"
114+
}
115+
]
116+
}
117+
`
118+
119+
var getParamJSON = `
120+
{
121+
"max": 1,
122+
"min": 0,
123+
"name": "innodb_file_per_table",
124+
"restart_required": true,
125+
"type": "integer"
126+
}
127+
`
128+
129+
var exampleConfig = os.Config{
130+
Created: "2014-07-31T18:56:09",
131+
DatastoreName: "mysql",
132+
DatastoreVersionID: "b00000b0-00b0-0b00-00b0-000b000000bb",
133+
DatastoreVersionName: "5.6",
134+
Description: "example_description",
135+
ID: "005a8bb7-a8df-40ee-b0b7-fc144641abc2",
136+
Name: "example-configuration-name",
137+
Updated: "2014-07-31T18:56:09",
138+
}
139+
140+
var exampleConfigWithValues = os.Config{
141+
Created: "2014-07-31T15:02:52",
142+
DatastoreName: "mysql",
143+
DatastoreVersionID: "b00000b0-00b0-0b00-00b0-000b000000bb",
144+
DatastoreVersionName: "5.6",
145+
Description: "example description",
146+
ID: "005a8bb7-a8df-40ee-b0b7-fc144641abc2",
147+
Name: "example-configuration-name",
148+
Updated: "2014-07-31T15:02:52",
149+
Values: map[string]interface{}{
150+
"collation_server": "latin1_swedish_ci",
151+
"connect_timeout": 120,
152+
},
153+
}

0 commit comments

Comments
 (0)