Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame^] | 1 | // +build fixtures |
| 2 | |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 3 | package stackevents |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/rackspace/gophercloud" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 14 | ) |
| 15 | |
| 16 | // FindExpected represents the expected object from a Find request. |
| 17 | var FindExpected = []Event{ |
| 18 | Event{ |
| 19 | ResourceName: "hello_world", |
| 20 | Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
| 21 | Links: []gophercloud.Link{ |
| 22 | gophercloud.Link{ |
| 23 | 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", |
| 24 | Rel: "self", |
| 25 | }, |
| 26 | gophercloud.Link{ |
| 27 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 28 | Rel: "resource", |
| 29 | }, |
| 30 | gophercloud.Link{ |
| 31 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 32 | Rel: "stack", |
| 33 | }, |
| 34 | }, |
| 35 | LogicalResourceID: "hello_world", |
| 36 | ResourceStatusReason: "state changed", |
| 37 | ResourceStatus: "CREATE_IN_PROGRESS", |
| 38 | PhysicalResourceID: "", |
| 39 | ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 40 | }, |
| 41 | Event{ |
| 42 | ResourceName: "hello_world", |
| 43 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
| 44 | Links: []gophercloud.Link{ |
| 45 | gophercloud.Link{ |
| 46 | 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", |
| 47 | Rel: "self", |
| 48 | }, |
| 49 | gophercloud.Link{ |
| 50 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 51 | Rel: "resource", |
| 52 | }, |
| 53 | gophercloud.Link{ |
| 54 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 55 | Rel: "stack", |
| 56 | }, |
| 57 | }, |
| 58 | LogicalResourceID: "hello_world", |
| 59 | ResourceStatusReason: "state changed", |
| 60 | ResourceStatus: "CREATE_COMPLETE", |
| 61 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 62 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | // FindOutput represents the response body from a Find request. |
| 67 | const FindOutput = ` |
| 68 | { |
| 69 | "events": [ |
| 70 | { |
| 71 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 72 | "event_time": "2015-02-05T21:33:11", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 73 | "links": [ |
| 74 | { |
| 75 | "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", |
| 76 | "rel": "self" |
| 77 | }, |
| 78 | { |
| 79 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 80 | "rel": "resource" |
| 81 | }, |
| 82 | { |
| 83 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 84 | "rel": "stack" |
| 85 | } |
| 86 | ], |
| 87 | "logical_resource_id": "hello_world", |
| 88 | "resource_status_reason": "state changed", |
| 89 | "resource_status": "CREATE_IN_PROGRESS", |
| 90 | "physical_resource_id": null, |
| 91 | "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" |
| 92 | }, |
| 93 | { |
| 94 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 95 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 96 | "links": [ |
| 97 | { |
| 98 | "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", |
| 99 | "rel": "self" |
| 100 | }, |
| 101 | { |
| 102 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 103 | "rel": "resource" |
| 104 | }, |
| 105 | { |
| 106 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 107 | "rel": "stack" |
| 108 | } |
| 109 | ], |
| 110 | "logical_resource_id": "hello_world", |
| 111 | "resource_status_reason": "state changed", |
| 112 | "resource_status": "CREATE_COMPLETE", |
| 113 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 114 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 115 | } |
| 116 | ] |
| 117 | }` |
| 118 | |
| 119 | // HandleFindSuccessfully creates an HTTP handler at `/stacks/postman_stack/events` |
| 120 | // on the test handler mux that responds with a `Find` response. |
| 121 | func HandleFindSuccessfully(t *testing.T, output string) { |
| 122 | th.Mux.HandleFunc("/stacks/postman_stack/events", func(w http.ResponseWriter, r *http.Request) { |
| 123 | th.TestMethod(t, r, "GET") |
| 124 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 125 | th.TestHeader(t, r, "Accept", "application/json") |
| 126 | |
| 127 | w.Header().Set("Content-Type", "application/json") |
| 128 | w.WriteHeader(http.StatusOK) |
| 129 | fmt.Fprintf(w, output) |
| 130 | }) |
| 131 | } |
| 132 | |
| 133 | // ListExpected represents the expected object from a List request. |
| 134 | var ListExpected = []Event{ |
| 135 | Event{ |
| 136 | ResourceName: "hello_world", |
| 137 | Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
| 138 | Links: []gophercloud.Link{ |
| 139 | gophercloud.Link{ |
| 140 | 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", |
| 141 | Rel: "self", |
| 142 | }, |
| 143 | gophercloud.Link{ |
| 144 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 145 | Rel: "resource", |
| 146 | }, |
| 147 | gophercloud.Link{ |
| 148 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 149 | Rel: "stack", |
| 150 | }, |
| 151 | }, |
| 152 | LogicalResourceID: "hello_world", |
| 153 | ResourceStatusReason: "state changed", |
| 154 | ResourceStatus: "CREATE_IN_PROGRESS", |
| 155 | PhysicalResourceID: "", |
| 156 | ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 157 | }, |
| 158 | Event{ |
| 159 | ResourceName: "hello_world", |
| 160 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
| 161 | Links: []gophercloud.Link{ |
| 162 | gophercloud.Link{ |
| 163 | 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", |
| 164 | Rel: "self", |
| 165 | }, |
| 166 | gophercloud.Link{ |
| 167 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 168 | Rel: "resource", |
| 169 | }, |
| 170 | gophercloud.Link{ |
| 171 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 172 | Rel: "stack", |
| 173 | }, |
| 174 | }, |
| 175 | LogicalResourceID: "hello_world", |
| 176 | ResourceStatusReason: "state changed", |
| 177 | ResourceStatus: "CREATE_COMPLETE", |
| 178 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 179 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 180 | }, |
| 181 | } |
| 182 | |
| 183 | // ListOutput represents the response body from a List request. |
| 184 | const ListOutput = ` |
| 185 | { |
| 186 | "events": [ |
| 187 | { |
| 188 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 189 | "event_time": "2015-02-05T21:33:11", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 190 | "links": [ |
| 191 | { |
| 192 | "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", |
| 193 | "rel": "self" |
| 194 | }, |
| 195 | { |
| 196 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 197 | "rel": "resource" |
| 198 | }, |
| 199 | { |
| 200 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 201 | "rel": "stack" |
| 202 | } |
| 203 | ], |
| 204 | "logical_resource_id": "hello_world", |
| 205 | "resource_status_reason": "state changed", |
| 206 | "resource_status": "CREATE_IN_PROGRESS", |
| 207 | "physical_resource_id": null, |
| 208 | "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" |
| 209 | }, |
| 210 | { |
| 211 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 212 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 213 | "links": [ |
| 214 | { |
| 215 | "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", |
| 216 | "rel": "self" |
| 217 | }, |
| 218 | { |
| 219 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 220 | "rel": "resource" |
| 221 | }, |
| 222 | { |
| 223 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 224 | "rel": "stack" |
| 225 | } |
| 226 | ], |
| 227 | "logical_resource_id": "hello_world", |
| 228 | "resource_status_reason": "state changed", |
| 229 | "resource_status": "CREATE_COMPLETE", |
| 230 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 231 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 232 | } |
| 233 | ] |
| 234 | }` |
| 235 | |
| 236 | // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events` |
| 237 | // on the test handler mux that responds with a `List` response. |
| 238 | func HandleListSuccessfully(t *testing.T, output string) { |
| 239 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events", func(w http.ResponseWriter, r *http.Request) { |
| 240 | th.TestMethod(t, r, "GET") |
| 241 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 242 | th.TestHeader(t, r, "Accept", "application/json") |
| 243 | |
| 244 | w.Header().Set("Content-Type", "application/json") |
| 245 | r.ParseForm() |
| 246 | marker := r.Form.Get("marker") |
| 247 | switch marker { |
| 248 | case "": |
| 249 | fmt.Fprintf(w, output) |
| 250 | case "93940999-7d40-44ae-8de4-19624e7b8d18": |
| 251 | fmt.Fprintf(w, `{"events":[]}`) |
| 252 | default: |
| 253 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 254 | } |
| 255 | }) |
| 256 | } |
| 257 | |
| 258 | // ListResourceEventsExpected represents the expected object from a ListResourceEvents request. |
| 259 | var ListResourceEventsExpected = []Event{ |
| 260 | Event{ |
| 261 | ResourceName: "hello_world", |
| 262 | Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
| 263 | Links: []gophercloud.Link{ |
| 264 | gophercloud.Link{ |
| 265 | 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", |
| 266 | Rel: "self", |
| 267 | }, |
| 268 | gophercloud.Link{ |
| 269 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 270 | Rel: "resource", |
| 271 | }, |
| 272 | gophercloud.Link{ |
| 273 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 274 | Rel: "stack", |
| 275 | }, |
| 276 | }, |
| 277 | LogicalResourceID: "hello_world", |
| 278 | ResourceStatusReason: "state changed", |
| 279 | ResourceStatus: "CREATE_IN_PROGRESS", |
| 280 | PhysicalResourceID: "", |
| 281 | ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 282 | }, |
| 283 | Event{ |
| 284 | ResourceName: "hello_world", |
| 285 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
| 286 | Links: []gophercloud.Link{ |
| 287 | gophercloud.Link{ |
| 288 | 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", |
| 289 | Rel: "self", |
| 290 | }, |
| 291 | gophercloud.Link{ |
| 292 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 293 | Rel: "resource", |
| 294 | }, |
| 295 | gophercloud.Link{ |
| 296 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 297 | Rel: "stack", |
| 298 | }, |
| 299 | }, |
| 300 | LogicalResourceID: "hello_world", |
| 301 | ResourceStatusReason: "state changed", |
| 302 | ResourceStatus: "CREATE_COMPLETE", |
| 303 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 304 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 305 | }, |
| 306 | } |
| 307 | |
| 308 | // ListResourceEventsOutput represents the response body from a ListResourceEvents request. |
| 309 | const ListResourceEventsOutput = ` |
| 310 | { |
| 311 | "events": [ |
| 312 | { |
| 313 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 314 | "event_time": "2015-02-05T21:33:11", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 315 | "links": [ |
| 316 | { |
| 317 | "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", |
| 318 | "rel": "self" |
| 319 | }, |
| 320 | { |
| 321 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 322 | "rel": "resource" |
| 323 | }, |
| 324 | { |
| 325 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 326 | "rel": "stack" |
| 327 | } |
| 328 | ], |
| 329 | "logical_resource_id": "hello_world", |
| 330 | "resource_status_reason": "state changed", |
| 331 | "resource_status": "CREATE_IN_PROGRESS", |
| 332 | "physical_resource_id": null, |
| 333 | "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" |
| 334 | }, |
| 335 | { |
| 336 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 337 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 338 | "links": [ |
| 339 | { |
| 340 | "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", |
| 341 | "rel": "self" |
| 342 | }, |
| 343 | { |
| 344 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 345 | "rel": "resource" |
| 346 | }, |
| 347 | { |
| 348 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 349 | "rel": "stack" |
| 350 | } |
| 351 | ], |
| 352 | "logical_resource_id": "hello_world", |
| 353 | "resource_status_reason": "state changed", |
| 354 | "resource_status": "CREATE_COMPLETE", |
| 355 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 356 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 357 | } |
| 358 | ] |
| 359 | }` |
| 360 | |
| 361 | // HandleListResourceEventsSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events` |
| 362 | // on the test handler mux that responds with a `ListResourceEvents` response. |
| 363 | func HandleListResourceEventsSuccessfully(t *testing.T, output string) { |
| 364 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events", func(w http.ResponseWriter, r *http.Request) { |
| 365 | th.TestMethod(t, r, "GET") |
| 366 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 367 | th.TestHeader(t, r, "Accept", "application/json") |
| 368 | |
| 369 | w.Header().Set("Content-Type", "application/json") |
| 370 | r.ParseForm() |
| 371 | marker := r.Form.Get("marker") |
| 372 | switch marker { |
| 373 | case "": |
| 374 | fmt.Fprintf(w, output) |
| 375 | case "93940999-7d40-44ae-8de4-19624e7b8d18": |
| 376 | fmt.Fprintf(w, `{"events":[]}`) |
| 377 | default: |
| 378 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 379 | } |
| 380 | }) |
| 381 | } |
| 382 | |
| 383 | // GetExpected represents the expected object from a Get request. |
| 384 | var GetExpected = &Event{ |
| 385 | ResourceName: "hello_world", |
| 386 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
| 387 | Links: []gophercloud.Link{ |
| 388 | gophercloud.Link{ |
| 389 | 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", |
| 390 | Rel: "self", |
| 391 | }, |
| 392 | gophercloud.Link{ |
| 393 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 394 | Rel: "resource", |
| 395 | }, |
| 396 | gophercloud.Link{ |
| 397 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 398 | Rel: "stack", |
| 399 | }, |
| 400 | }, |
| 401 | LogicalResourceID: "hello_world", |
| 402 | ResourceStatusReason: "state changed", |
| 403 | ResourceStatus: "CREATE_COMPLETE", |
| 404 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 405 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 406 | } |
| 407 | |
| 408 | // GetOutput represents the response body from a Get request. |
| 409 | const GetOutput = ` |
| 410 | { |
| 411 | "event":{ |
| 412 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 413 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 414 | "links": [ |
| 415 | { |
| 416 | "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", |
| 417 | "rel": "self" |
| 418 | }, |
| 419 | { |
| 420 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 421 | "rel": "resource" |
| 422 | }, |
| 423 | { |
| 424 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 425 | "rel": "stack" |
| 426 | } |
| 427 | ], |
| 428 | "logical_resource_id": "hello_world", |
| 429 | "resource_status_reason": "state changed", |
| 430 | "resource_status": "CREATE_COMPLETE", |
| 431 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 432 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 433 | } |
| 434 | }` |
| 435 | |
| 436 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events/93940999-7d40-44ae-8de4-19624e7b8d18` |
| 437 | // on the test handler mux that responds with a `Get` response. |
| 438 | func HandleGetSuccessfully(t *testing.T, output string) { |
| 439 | 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) { |
| 440 | th.TestMethod(t, r, "GET") |
| 441 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 442 | th.TestHeader(t, r, "Accept", "application/json") |
| 443 | |
| 444 | w.Header().Set("Content-Type", "application/json") |
| 445 | w.WriteHeader(http.StatusOK) |
| 446 | fmt.Fprintf(w, output) |
| 447 | }) |
| 448 | } |