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