/
fixtures.go
232 lines (212 loc) · 8.79 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
package testing
import (
"fmt"
"net/http"
s "strings"
"testing"
"time"
"github.com/gophercloud/gophercloud"
transferRequests "github.com/gophercloud/gophercloud/openstack/dns/v2/transfer/request"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
// ListOutput is a sample response to a List call.
const ListOutput = `
{
"transfer_requests": [
{
"id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
"zone_id": "a6a8515c-5d80-48c0-955b-fde631b59791",
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
"target_project_id": "05d98711-b3a1-4264-a395-f46383671ee6",
"description": "This is a first example zone transfer request.",
"key": "KJSDH23Z",
"status": "ACTIVE",
"zone_name": "example1.org.",
"created_at": "2020-10-12T08:38:58.000000",
"links": {
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
}
},
{
"id": "34c4561c-9205-4386-9df5-167436f5a222",
"zone_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
"target_project_id": "05d98711-b3a1-4264-a395-f46383671ee6",
"description": "This is second example zone transfer request.",
"key": "KSDFJ22H",
"status": "ACTIVE",
"zone_name": "example2.org.",
"created_at": "2020-10-12T09:38:58.000000",
"updated_at": "2020-10-12T10:38:58.000000",
"links": {
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/34c4561c-9205-4386-9df5-167436f5a222"
}
}
],
"links": {
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests"
}
}
`
// GetOutput is a sample response to a Get call.
const GetOutput = `
{
"id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
"zone_id": "a6a8515c-5d80-48c0-955b-fde631b59791",
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
"target_project_id": "05d98711-b3a1-4264-a395-f46383671ee6",
"description": "This is a first example zone transfer request.",
"key": "KJSDH23Z",
"status": "ACTIVE",
"zone_name": "example1.org.",
"created_at": "2020-10-12T08:38:58.000000",
"links": {
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
}
}
`
// FirstTransferRequest is the first result in ListOutput
var FirstTransferRequestCreatedAt, _ = time.Parse(gophercloud.RFC3339MilliNoZ, "2020-10-12T08:38:58.000000")
var FirstTransferRequest = transferRequests.TransferRequest{
ID: "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
ZoneID: "a6a8515c-5d80-48c0-955b-fde631b59791",
ProjectID: "4335d1f0-f793-11e2-b778-0800200c9a66",
TargetProjectID: "05d98711-b3a1-4264-a395-f46383671ee6",
ZoneName: "example1.org.",
Key: "KJSDH23Z",
Description: "This is a first example zone transfer request.",
Status: "ACTIVE",
CreatedAt: FirstTransferRequestCreatedAt,
Links: map[string]interface{}{
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
},
}
// SecondTransferRequest is the second result in ListOutput
var SecondTransferRequestCreatedAt, _ = time.Parse(gophercloud.RFC3339MilliNoZ, "2020-10-12T09:38:58.000000")
var SecondTransferRequestUpdatedAt, _ = time.Parse(gophercloud.RFC3339MilliNoZ, "2020-10-12T10:38:58.000000")
var SecondTransferRequest = transferRequests.TransferRequest{
ID: "34c4561c-9205-4386-9df5-167436f5a222",
ZoneID: "572ba08c-d929-4c70-8e42-03824bb24ca2",
ProjectID: "4335d1f0-f793-11e2-b778-0800200c9a66",
TargetProjectID: "05d98711-b3a1-4264-a395-f46383671ee6",
ZoneName: "example2.org.",
Key: "KSDFJ22H",
Description: "This is second example zone transfer request.",
Status: "ACTIVE",
CreatedAt: SecondTransferRequestCreatedAt,
UpdatedAt: SecondTransferRequestUpdatedAt,
Links: map[string]interface{}{
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/34c4561c-9205-4386-9df5-167436f5a222",
},
}
// ExpectedTransferRequestsSlice is the slice of results that should be parsed
// from ListOutput, in the expected order.
var ExpectedTransferRequestsSlice = []transferRequests.TransferRequest{FirstTransferRequest, SecondTransferRequest}
// HandleListSuccessfully configures the test server to respond to a List request.
func HandleListSuccessfully(t *testing.T) {
baseURL := "/zones/tasks/transfer_requests"
th.Mux.HandleFunc(baseURL,
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 List request.
func HandleGetSuccessfully(t *testing.T) {
baseURL := "/zones/tasks/transfer_requests"
th.Mux.HandleFunc(s.Join([]string{baseURL, FirstTransferRequest.ID}, "/"),
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)
})
}
// CreateTransferRequest is a sample request to create a zone.
const CreateTransferRequest = `
{
"target_project_id": "05d98711-b3a1-4264-a395-f46383671ee6",
"description": "This is a first example zone transfer request."
}
`
// CreateZoneResponse is a sample response to a create request.
const CreateTransferRequestResponse = `
{
"id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
"zone_id": "a6a8515c-5d80-48c0-955b-fde631b59791",
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
"target_project_id": "05d98711-b3a1-4264-a395-f46383671ee6",
"description": "This is a first example zone transfer request.",
"key": "KJSDH23Z",
"status": "ACTIVE",
"zone_name": "example1.org.",
"created_at": "2020-10-12T08:38:58.000000",
"links": {
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
}
}
`
// CreatedTransferRequest is the expected created zone transfer request.
var CreatedTransferRequest = FirstTransferRequest
// HandleTransferRequestCreationSuccessfully configures the test server to respond to a Create request.
func HandleCreateSuccessfully(t *testing.T) {
createURL := "/zones/a6a8515c-5d80-48c0-955b-fde631b59791/tasks/transfer_requests"
th.Mux.HandleFunc(createURL,
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, CreateTransferRequest)
w.WriteHeader(http.StatusCreated)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, CreateTransferRequestResponse)
})
}
// UpdateTransferRequest is a sample request to update a zone transfer request.
const UpdateTransferRequest = `
{
"description": "Updated Description"
}
`
// UpdatedTransferRequestResponse is a sample response to update a zone transfer request.
const UpdatedTransferRequestResponse = `
{
"id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
"zone_id": "a6a8515c-5d80-48c0-955b-fde631b59791",
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
"target_project_id": "05d98711-b3a1-4264-a395-f46383671ee6",
"description": "Updated Description",
"key": "KJSDH23Z",
"status": "ACTIVE",
"zone_name": "example1.org.",
"created_at": "2020-10-12T08:38:58.000000",
"links": {
"self": "https://127.0.0.1:9001/v2/zones/tasks/transfer_requests/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
}
}
`
// HandleTransferRequestUpdateSuccessfully configures the test server to respond to an Update request.
func HandleUpdateSuccessfully(t *testing.T) {
baseURL := "/zones/tasks/transfer_requests"
th.Mux.HandleFunc(s.Join([]string{baseURL, FirstTransferRequest.ID}, "/"),
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PATCH")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, UpdateTransferRequest)
w.WriteHeader(http.StatusOK)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, UpdatedTransferRequestResponse)
})
}
// HandleTransferRequestDeleteSuccessfully configures the test server to respond to an Delete request.
func HandleDeleteSuccessfully(t *testing.T) {
baseURL := "/zones/tasks/transfer_requests"
th.Mux.HandleFunc(s.Join([]string{baseURL, FirstTransferRequest.ID}, "/"),
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
}