blob: 2bea29088f750bd58ddae3525c00eb50d53f4727 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Jon Perritt7cbb42c2015-02-08 21:13:08 -07002
3import (
4 "fmt"
5 "net/http"
6 "testing"
7 "time"
8
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02009 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +020010 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/orchestration/v1/stackevents"
11 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
12 fake "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
Jon Perritt7cbb42c2015-02-08 21:13:08 -070013)
14
15// FindExpected represents the expected object from a Find request.
jrperritt3d966162016-06-06 14:08:54 -050016var FindExpected = []stackevents.Event{
17 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070018 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -060019 Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -070020 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -050021 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070022 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
23 Rel: "self",
24 },
jrperritt3d966162016-06-06 14:08:54 -050025 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070026 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
27 Rel: "resource",
28 },
jrperritt3d966162016-06-06 14:08:54 -050029 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070030 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
31 Rel: "stack",
32 },
33 },
34 LogicalResourceID: "hello_world",
35 ResourceStatusReason: "state changed",
36 ResourceStatus: "CREATE_IN_PROGRESS",
37 PhysicalResourceID: "",
38 ID: "06feb26f-9298-4a9b-8749-9d770e5d577a",
39 },
jrperritt3d966162016-06-06 14:08:54 -050040 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070041 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -060042 Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -070043 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -050044 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070045 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
46 Rel: "self",
47 },
jrperritt3d966162016-06-06 14:08:54 -050048 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070049 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
50 Rel: "resource",
51 },
jrperritt3d966162016-06-06 14:08:54 -050052 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -070053 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
54 Rel: "stack",
55 },
56 },
57 LogicalResourceID: "hello_world",
58 ResourceStatusReason: "state changed",
59 ResourceStatus: "CREATE_COMPLETE",
60 PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf",
61 ID: "93940999-7d40-44ae-8de4-19624e7b8d18",
62 },
63}
64
65// FindOutput represents the response body from a Find request.
66const FindOutput = `
67{
68 "events": [
69 {
70 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -050071 "event_time": "2015-02-05T21:33:11",
Jon Perritt7cbb42c2015-02-08 21:13:08 -070072 "links": [
73 {
74 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
75 "rel": "self"
76 },
77 {
78 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
79 "rel": "resource"
80 },
81 {
82 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
83 "rel": "stack"
84 }
85 ],
86 "logical_resource_id": "hello_world",
87 "resource_status_reason": "state changed",
88 "resource_status": "CREATE_IN_PROGRESS",
89 "physical_resource_id": null,
90 "id": "06feb26f-9298-4a9b-8749-9d770e5d577a"
91 },
92 {
93 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -050094 "event_time": "2015-02-05T21:33:27",
Jon Perritt7cbb42c2015-02-08 21:13:08 -070095 "links": [
96 {
97 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
98 "rel": "self"
99 },
100 {
101 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
102 "rel": "resource"
103 },
104 {
105 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
106 "rel": "stack"
107 }
108 ],
109 "logical_resource_id": "hello_world",
110 "resource_status_reason": "state changed",
111 "resource_status": "CREATE_COMPLETE",
112 "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
113 "id": "93940999-7d40-44ae-8de4-19624e7b8d18"
114 }
115 ]
116}`
117
118// HandleFindSuccessfully creates an HTTP handler at `/stacks/postman_stack/events`
119// on the test handler mux that responds with a `Find` response.
120func HandleFindSuccessfully(t *testing.T, output string) {
121 th.Mux.HandleFunc("/stacks/postman_stack/events", func(w http.ResponseWriter, r *http.Request) {
122 th.TestMethod(t, r, "GET")
123 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
124 th.TestHeader(t, r, "Accept", "application/json")
125
126 w.Header().Set("Content-Type", "application/json")
127 w.WriteHeader(http.StatusOK)
128 fmt.Fprintf(w, output)
129 })
130}
131
132// ListExpected represents the expected object from a List request.
jrperritt3d966162016-06-06 14:08:54 -0500133var ListExpected = []stackevents.Event{
134 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700135 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -0600136 Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700137 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500138 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700139 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
140 Rel: "self",
141 },
jrperritt3d966162016-06-06 14:08:54 -0500142 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700143 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
144 Rel: "resource",
145 },
jrperritt3d966162016-06-06 14:08:54 -0500146 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700147 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
148 Rel: "stack",
149 },
150 },
151 LogicalResourceID: "hello_world",
152 ResourceStatusReason: "state changed",
153 ResourceStatus: "CREATE_IN_PROGRESS",
154 PhysicalResourceID: "",
155 ID: "06feb26f-9298-4a9b-8749-9d770e5d577a",
156 },
jrperritt3d966162016-06-06 14:08:54 -0500157 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700158 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -0600159 Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700160 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500161 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700162 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
163 Rel: "self",
164 },
jrperritt3d966162016-06-06 14:08:54 -0500165 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700166 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
167 Rel: "resource",
168 },
jrperritt3d966162016-06-06 14:08:54 -0500169 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700170 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
171 Rel: "stack",
172 },
173 },
174 LogicalResourceID: "hello_world",
175 ResourceStatusReason: "state changed",
176 ResourceStatus: "CREATE_COMPLETE",
177 PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf",
178 ID: "93940999-7d40-44ae-8de4-19624e7b8d18",
179 },
180}
181
182// ListOutput represents the response body from a List request.
183const ListOutput = `
184{
185 "events": [
186 {
187 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -0500188 "event_time": "2015-02-05T21:33:11",
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700189 "links": [
190 {
191 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
192 "rel": "self"
193 },
194 {
195 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
196 "rel": "resource"
197 },
198 {
199 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
200 "rel": "stack"
201 }
202 ],
203 "logical_resource_id": "hello_world",
204 "resource_status_reason": "state changed",
205 "resource_status": "CREATE_IN_PROGRESS",
206 "physical_resource_id": null,
207 "id": "06feb26f-9298-4a9b-8749-9d770e5d577a"
208 },
209 {
210 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -0500211 "event_time": "2015-02-05T21:33:27",
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700212 "links": [
213 {
214 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
215 "rel": "self"
216 },
217 {
218 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
219 "rel": "resource"
220 },
221 {
222 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
223 "rel": "stack"
224 }
225 ],
226 "logical_resource_id": "hello_world",
227 "resource_status_reason": "state changed",
228 "resource_status": "CREATE_COMPLETE",
229 "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
230 "id": "93940999-7d40-44ae-8de4-19624e7b8d18"
231 }
232 ]
233}`
234
235// HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events`
236// on the test handler mux that responds with a `List` response.
237func HandleListSuccessfully(t *testing.T, output string) {
238 th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events", func(w http.ResponseWriter, r *http.Request) {
239 th.TestMethod(t, r, "GET")
240 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
241 th.TestHeader(t, r, "Accept", "application/json")
242
243 w.Header().Set("Content-Type", "application/json")
244 r.ParseForm()
245 marker := r.Form.Get("marker")
246 switch marker {
247 case "":
248 fmt.Fprintf(w, output)
249 case "93940999-7d40-44ae-8de4-19624e7b8d18":
250 fmt.Fprintf(w, `{"events":[]}`)
251 default:
252 t.Fatalf("Unexpected marker: [%s]", marker)
253 }
254 })
255}
256
257// ListResourceEventsExpected represents the expected object from a ListResourceEvents request.
jrperritt3d966162016-06-06 14:08:54 -0500258var ListResourceEventsExpected = []stackevents.Event{
259 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700260 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -0600261 Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700262 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500263 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700264 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
265 Rel: "self",
266 },
jrperritt3d966162016-06-06 14:08:54 -0500267 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700268 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
269 Rel: "resource",
270 },
jrperritt3d966162016-06-06 14:08:54 -0500271 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700272 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
273 Rel: "stack",
274 },
275 },
276 LogicalResourceID: "hello_world",
277 ResourceStatusReason: "state changed",
278 ResourceStatus: "CREATE_IN_PROGRESS",
279 PhysicalResourceID: "",
280 ID: "06feb26f-9298-4a9b-8749-9d770e5d577a",
281 },
jrperritt3d966162016-06-06 14:08:54 -0500282 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700283 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -0600284 Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700285 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500286 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700287 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
288 Rel: "self",
289 },
jrperritt3d966162016-06-06 14:08:54 -0500290 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700291 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
292 Rel: "resource",
293 },
jrperritt3d966162016-06-06 14:08:54 -0500294 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700295 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
296 Rel: "stack",
297 },
298 },
299 LogicalResourceID: "hello_world",
300 ResourceStatusReason: "state changed",
301 ResourceStatus: "CREATE_COMPLETE",
302 PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf",
303 ID: "93940999-7d40-44ae-8de4-19624e7b8d18",
304 },
305}
306
307// ListResourceEventsOutput represents the response body from a ListResourceEvents request.
308const ListResourceEventsOutput = `
309{
310 "events": [
311 {
312 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -0500313 "event_time": "2015-02-05T21:33:11",
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700314 "links": [
315 {
316 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
317 "rel": "self"
318 },
319 {
320 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
321 "rel": "resource"
322 },
323 {
324 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
325 "rel": "stack"
326 }
327 ],
328 "logical_resource_id": "hello_world",
329 "resource_status_reason": "state changed",
330 "resource_status": "CREATE_IN_PROGRESS",
331 "physical_resource_id": null,
332 "id": "06feb26f-9298-4a9b-8749-9d770e5d577a"
333 },
334 {
335 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -0500336 "event_time": "2015-02-05T21:33:27",
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700337 "links": [
338 {
339 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
340 "rel": "self"
341 },
342 {
343 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
344 "rel": "resource"
345 },
346 {
347 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
348 "rel": "stack"
349 }
350 ],
351 "logical_resource_id": "hello_world",
352 "resource_status_reason": "state changed",
353 "resource_status": "CREATE_COMPLETE",
354 "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
355 "id": "93940999-7d40-44ae-8de4-19624e7b8d18"
356 }
357 ]
358}`
359
360// HandleListResourceEventsSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events`
361// on the test handler mux that responds with a `ListResourceEvents` response.
362func HandleListResourceEventsSuccessfully(t *testing.T, output string) {
363 th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events", func(w http.ResponseWriter, r *http.Request) {
364 th.TestMethod(t, r, "GET")
365 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
366 th.TestHeader(t, r, "Accept", "application/json")
367
368 w.Header().Set("Content-Type", "application/json")
369 r.ParseForm()
370 marker := r.Form.Get("marker")
371 switch marker {
372 case "":
373 fmt.Fprintf(w, output)
374 case "93940999-7d40-44ae-8de4-19624e7b8d18":
375 fmt.Fprintf(w, `{"events":[]}`)
376 default:
377 t.Fatalf("Unexpected marker: [%s]", marker)
378 }
379 })
380}
381
382// GetExpected represents the expected object from a Get request.
jrperritt3d966162016-06-06 14:08:54 -0500383var GetExpected = &stackevents.Event{
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700384 ResourceName: "hello_world",
jrperritt98d01622017-01-12 14:24:42 -0600385 Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC),
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700386 Links: []gophercloud.Link{
jrperritt3d966162016-06-06 14:08:54 -0500387 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700388 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
389 Rel: "self",
390 },
jrperritt3d966162016-06-06 14:08:54 -0500391 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700392 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
393 Rel: "resource",
394 },
jrperritt3d966162016-06-06 14:08:54 -0500395 {
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700396 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
397 Rel: "stack",
398 },
399 },
400 LogicalResourceID: "hello_world",
401 ResourceStatusReason: "state changed",
402 ResourceStatus: "CREATE_COMPLETE",
403 PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf",
404 ID: "93940999-7d40-44ae-8de4-19624e7b8d18",
405}
406
407// GetOutput represents the response body from a Get request.
408const GetOutput = `
409{
410 "event":{
411 "resource_name": "hello_world",
Pratik Mallyae1b6cbb2015-09-09 14:24:14 -0500412 "event_time": "2015-02-05T21:33:27",
Jon Perritt7cbb42c2015-02-08 21:13:08 -0700413 "links": [
414 {
415 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
416 "rel": "self"
417 },
418 {
419 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
420 "rel": "resource"
421 },
422 {
423 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
424 "rel": "stack"
425 }
426 ],
427 "logical_resource_id": "hello_world",
428 "resource_status_reason": "state changed",
429 "resource_status": "CREATE_COMPLETE",
430 "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
431 "id": "93940999-7d40-44ae-8de4-19624e7b8d18"
432 }
433}`
434
435// HandleGetSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events/93940999-7d40-44ae-8de4-19624e7b8d18`
436// on the test handler mux that responds with a `Get` response.
437func HandleGetSuccessfully(t *testing.T, output string) {
438 th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events/93940999-7d40-44ae-8de4-19624e7b8d18", func(w http.ResponseWriter, r *http.Request) {
439 th.TestMethod(t, r, "GET")
440 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
441 th.TestHeader(t, r, "Accept", "application/json")
442
443 w.Header().Set("Content-Type", "application/json")
444 w.WriteHeader(http.StatusOK)
445 fmt.Fprintf(w, output)
446 })
447}