forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
236 lines (213 loc) · 6.27 KB
/
fixtures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
// ListOutput is a sample response to a List call.
const ListOutput = `
{
"server_groups": [
{
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"name": "test",
"policies": [
"anti-affinity"
],
"members": [],
"metadata": {}
},
{
"id": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
"name": "test2",
"policies": [
"affinity"
],
"members": [],
"metadata": {}
}
]
}
`
// GetOutput is a sample response to a Get call.
const GetOutput = `
{
"server_group": {
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"name": "test",
"policies": [
"anti-affinity"
],
"members": [],
"metadata": {}
}
}
`
// GetOutputMicroversion is a sample response to a Get call with microversion set to 2.64
const GetOutputMicroversion = `
{
"server_group": {
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"name": "test",
"policies": [
"anti-affinity"
],
"policy": "anti-affinity",
"rules": {
"max_server_per_host": 3
},
"members": [],
"metadata": {}
}
}
`
// CreateOutput is a sample response to a Post call
const CreateOutput = `
{
"server_group": {
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"name": "test",
"policies": [
"anti-affinity"
],
"members": [],
"metadata": {}
}
}
`
// CreateOutputMicroversion is a sample response to a Post call with microversion set to 2.64
const CreateOutputMicroversion = `
{
"server_group": {
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"name": "test",
"policies": [
"anti-affinity"
],
"policy": "anti-affinity",
"rules": {
"max_server_per_host": 3
},
"members": [],
"metadata": {}
}
}
`
// FirstServerGroup is the first result in ListOutput.
var FirstServerGroup = servergroups.ServerGroup{
ID: "616fb98f-46ca-475e-917e-2563e5a8cd19",
Name: "test",
Policies: []string{
"anti-affinity",
},
Members: []string{},
Metadata: map[string]interface{}{},
}
// SecondServerGroup is the second result in ListOutput.
var SecondServerGroup = servergroups.ServerGroup{
ID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
Name: "test2",
Policies: []string{
"affinity",
},
Members: []string{},
Metadata: map[string]interface{}{},
}
// ExpectedServerGroupSlice is the slice of results that should be parsed
// from ListOutput, in the expected order.
var ExpectedServerGroupSlice = []servergroups.ServerGroup{FirstServerGroup, SecondServerGroup}
// CreatedServerGroup is the parsed result from CreateOutput.
var CreatedServerGroup = servergroups.ServerGroup{
ID: "616fb98f-46ca-475e-917e-2563e5a8cd19",
Name: "test",
Policies: []string{
"anti-affinity",
},
Members: []string{},
Metadata: map[string]interface{}{},
}
// HandleListSuccessfully configures the test server to respond to a List request.
func HandleListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-server-groups", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, ListOutput)
})
}
// HandleGetSuccessfully configures the test server to respond to a Get request
// for an existing server group
func HandleGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-server-groups/4d8c3732-a248-40ed-bebc-539a6ffd25c0", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, GetOutput)
})
}
// HandleGetMicroversionSuccessfully configures the test server to respond to a Get request
// for an existing server group with microversion set to 2.64
func HandleGetMicroversionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-server-groups/4d8c3732-a248-40ed-bebc-539a6ffd25c0", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, GetOutputMicroversion)
})
}
// HandleCreateSuccessfully configures the test server to respond to a Create request
// for a new server group
func HandleCreateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-server-groups", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `
{
"server_group": {
"name": "test",
"policies": [
"anti-affinity"
]
}
}
`)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, CreateOutput)
})
}
// HandleCreateMicroversionSuccessfully configures the test server to respond to a Create request
// for a new server group with microversion set to 2.64
func HandleCreateMicroversionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-server-groups", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `
{
"server_group": {
"name": "test",
"policies": [
"anti-affinity"
],
"policy": "anti-affinity",
"rules": {
"max_server_per_host": 3
}
}
}
`)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, CreateOutputMicroversion)
})
}
// HandleDeleteSuccessfully configures the test server to respond to a Delete request for a
// an existing server group
func HandleDeleteSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/os-server-groups/616fb98f-46ca-475e-917e-2563e5a8cd19", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}