File: fixtures.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 10,224 kB
  • sloc: sh: 125; makefile: 21
file content (290 lines) | stat: -rw-r--r-- 8,811 bytes parent folder | download
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package testing

import (
	"fmt"
	"net/http"
	"testing"
	"time"

	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

// ServiceListBodyPre253 represents a raw service list from the Compute API
// with microversion older than 2.53.
const ServiceListBodyPre253 = `
{
    "services": [
        {
            "id": 1,
            "binary": "nova-scheduler",
            "disabled_reason": "test1",
            "host": "host1",
            "state": "up",
            "status": "disabled",
            "updated_at": "2012-10-29T13:42:02.000000",
            "forced_down": false,
            "zone": "internal"
        },
        {
            "id": 2,
            "binary": "nova-compute",
            "disabled_reason": "test2",
            "host": "host1",
            "state": "up",
            "status": "disabled",
            "updated_at": "2012-10-29T13:42:05.000000",
            "forced_down": false,
            "zone": "nova"
        },
        {
            "id": 3,
            "binary": "nova-scheduler",
            "disabled_reason": null,
            "host": "host2",
            "state": "down",
            "status": "enabled",
            "updated_at": "2012-09-19T06:55:34.000000",
            "forced_down": false,
            "zone": "internal"
        },
        {
            "id": 4,
            "binary": "nova-compute",
            "disabled_reason": "test4",
            "host": "host2",
            "state": "down",
            "status": "disabled",
            "updated_at": "2012-09-18T08:03:38.000000",
            "forced_down": false,
            "zone": "nova"
        }
    ]
}
`

var (
	// FirstFakeServicePre253 represents the first service from the
	// ServiceListBodyPre253.
	FirstFakeServicePre253 = services.Service{
		Binary:         "nova-scheduler",
		DisabledReason: "test1",
		Host:           "host1",
		ID:             "1",
		State:          "up",
		Status:         "disabled",
		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC),
		Zone:           "internal",
	}

	// SecondFakeServicePre253 represents the second service from the
	// ServiceListBodyPre253.
	SecondFakeServicePre253 = services.Service{
		Binary:         "nova-compute",
		DisabledReason: "test2",
		Host:           "host1",
		ID:             "2",
		State:          "up",
		Status:         "disabled",
		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 5, 0, time.UTC),
		Zone:           "nova",
	}

	// ThirdFakeServicePre253 represents the third service from the
	// ServiceListBodyPre253.
	ThirdFakeServicePre253 = services.Service{
		Binary:         "nova-scheduler",
		DisabledReason: "",
		Host:           "host2",
		ID:             "3",
		State:          "down",
		Status:         "enabled",
		UpdatedAt:      time.Date(2012, 9, 19, 6, 55, 34, 0, time.UTC),
		Zone:           "internal",
	}

	// FourthFakeServicePre253 represents the fourth service from the
	// ServiceListBodyPre253.
	FourthFakeServicePre253 = services.Service{
		Binary:         "nova-compute",
		DisabledReason: "test4",
		Host:           "host2",
		ID:             "4",
		State:          "down",
		Status:         "disabled",
		UpdatedAt:      time.Date(2012, 9, 18, 8, 3, 38, 0, time.UTC),
		Zone:           "nova",
	}
)

// ServiceListBody represents a raw service list result with Pike+ release.
const ServiceListBody = `
{
    "services": [
        {
            "id": "4c720fa0-02c3-4834-8279-9eecf9edb6cb",
            "binary": "nova-scheduler",
            "disabled_reason": "test1",
            "host": "host1",
            "state": "up",
            "status": "disabled",
            "updated_at": "2012-10-29T13:42:02.000000",
            "forced_down": false,
            "zone": "internal"
        },
        {
            "id": "1fdfec3e-ee03-4e36-b99b-71cf2967b70c",
            "binary": "nova-compute",
            "disabled_reason": "test2",
            "host": "host1",
            "state": "up",
            "status": "disabled",
            "updated_at": "2012-10-29T13:42:05.000000",
            "forced_down": false,
            "zone": "nova"
        },
        {
            "id": "bd0b2e30-809e-4160-bd3d-f23ca30e9b68",
            "binary": "nova-scheduler",
            "disabled_reason": null,
            "host": "host2",
            "state": "down",
            "status": "enabled",
            "updated_at": "2012-09-19T06:55:34.000000",
            "forced_down": false,
            "zone": "internal"
        },
        {
            "id": "fe41c476-33e2-4ac3-ad21-3ffaf1b9c644",
            "binary": "nova-compute",
            "disabled_reason": "test4",
            "host": "host2",
            "state": "down",
            "status": "disabled",
            "updated_at": "2012-09-18T08:03:38.000000",
            "forced_down": false,
            "zone": "nova"
        }
    ]
}
`

var (
	// FirstFakeService represents the first service from the ServiceListBody.
	FirstFakeService = services.Service{
		Binary:         "nova-scheduler",
		DisabledReason: "test1",
		Host:           "host1",
		ID:             "4c720fa0-02c3-4834-8279-9eecf9edb6cb",
		State:          "up",
		Status:         "disabled",
		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC),
		Zone:           "internal",
	}

	// SecondFakeService represents the second service from the ServiceListBody.
	SecondFakeService = services.Service{
		Binary:         "nova-compute",
		DisabledReason: "test2",
		Host:           "host1",
		ID:             "1fdfec3e-ee03-4e36-b99b-71cf2967b70c",
		State:          "up",
		Status:         "disabled",
		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 5, 0, time.UTC),
		Zone:           "nova",
	}

	// ThirdFakeService represents the third service from the ServiceListBody.
	ThirdFakeService = services.Service{
		Binary:         "nova-scheduler",
		DisabledReason: "",
		Host:           "host2",
		ID:             "bd0b2e30-809e-4160-bd3d-f23ca30e9b68",
		State:          "down",
		Status:         "enabled",
		UpdatedAt:      time.Date(2012, 9, 19, 6, 55, 34, 0, time.UTC),
		Zone:           "internal",
	}

	// FourthFakeService represents the fourth service from the ServiceListBody.
	FourthFakeService = services.Service{
		Binary:         "nova-compute",
		DisabledReason: "test4",
		Host:           "host2",
		ID:             "fe41c476-33e2-4ac3-ad21-3ffaf1b9c644",
		State:          "down",
		Status:         "disabled",
		UpdatedAt:      time.Date(2012, 9, 18, 8, 3, 38, 0, time.UTC),
		Zone:           "nova",
	}
)

// ServiceUpdate represents a raw service from the Compute service update API
const ServiceUpdate = `
{
	"service":
	{
		"id": 1,
		"binary": "nova-scheduler",
		"disabled_reason": "test1",
		"host": "host1",
		"state": "up",
		"status": "disabled",
		"updated_at": "2012-10-29T13:42:02.000000",
		"forced_down": false,
		"zone": "internal"
	}
}
`

//FakeServiceUpdateBody represents the updated service
var FakeServiceUpdateBody = services.Service{
	Binary:         "nova-scheduler",
	DisabledReason: "test1",
	ForcedDown:     false,
	Host:           "host1",
	ID:             "1",
	State:          "up",
	Status:         "disabled",
	UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC),
	Zone:           "internal",
}

// HandleListPre253Successfully configures the test server to respond to a List
// request to a Compute server API pre 2.53 microversion release.
func HandleListPre253Successfully(t *testing.T) {
	th.Mux.HandleFunc("/os-services", 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, ServiceListBodyPre253)
	})
}

// HandleListSuccessfully configures the test server to respond to a List
// request to a Compute server with Pike+ release.
func HandleListSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/os-services", 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, ServiceListBody)
	})
}

// HandleUpdateSuccessfully configures the test server to respond to a Update
// request to a Compute server with Pike+ release.
func HandleUpdateSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/os-services/fake-service-id", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "PUT")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
		th.TestHeader(t, r, "Accept", "application/json")
		th.TestHeader(t, r, "Content-Type", "application/json")
		th.TestJSONRequest(t, r, `{"status": "disabled"}`)

		fmt.Fprintf(w, ServiceUpdate)
	})
}