github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/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/vnpaycloud-console/gophercloud/v2" 10 "github.com/vnpaycloud-console/gophercloud/v2/openstack/orchestration/v1/stackevents" 11 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 12 fake "github.com/vnpaycloud-console/gophercloud/v2/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.Fprint(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 if err := r.ParseForm(); err != nil { 248 t.Errorf("Failed to parse request form %v", err) 249 } 250 marker := r.Form.Get("marker") 251 switch marker { 252 case "": 253 fmt.Fprint(w, output) 254 case "93940999-7d40-44ae-8de4-19624e7b8d18": 255 fmt.Fprint(w, `{"events":[]}`) 256 default: 257 t.Fatalf("Unexpected marker: [%s]", marker) 258 } 259 }) 260 } 261 262 // ListResourceEventsExpected represents the expected object from a ListResourceEvents request. 263 var ListResourceEventsExpected = []stackevents.Event{ 264 { 265 ResourceName: "hello_world", 266 Time: Timestamp1, 267 Links: []gophercloud.Link{ 268 { 269 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", 270 Rel: "self", 271 }, 272 { 273 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", 274 Rel: "resource", 275 }, 276 { 277 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", 278 Rel: "stack", 279 }, 280 }, 281 LogicalResourceID: "hello_world", 282 ResourceStatusReason: "state changed", 283 ResourceStatus: "CREATE_IN_PROGRESS", 284 PhysicalResourceID: "", 285 ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", 286 }, 287 { 288 ResourceName: "hello_world", 289 Time: Timestamp2, 290 Links: []gophercloud.Link{ 291 { 292 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", 293 Rel: "self", 294 }, 295 { 296 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", 297 Rel: "resource", 298 }, 299 { 300 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", 301 Rel: "stack", 302 }, 303 }, 304 LogicalResourceID: "hello_world", 305 ResourceStatusReason: "state changed", 306 ResourceStatus: "CREATE_COMPLETE", 307 PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", 308 ID: "93940999-7d40-44ae-8de4-19624e7b8d18", 309 }, 310 } 311 312 // ListResourceEventsOutput represents the response body from a ListResourceEvents request. 313 const ListResourceEventsOutput = ` 314 { 315 "events": [ 316 { 317 "resource_name": "hello_world", 318 "event_time": "2018-06-26T07:58:17Z", 319 "links": [ 320 { 321 "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", 322 "rel": "self" 323 }, 324 { 325 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", 326 "rel": "resource" 327 }, 328 { 329 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", 330 "rel": "stack" 331 } 332 ], 333 "logical_resource_id": "hello_world", 334 "resource_status_reason": "state changed", 335 "resource_status": "CREATE_IN_PROGRESS", 336 "physical_resource_id": null, 337 "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" 338 }, 339 { 340 "resource_name": "hello_world", 341 "event_time": "2018-06-26T07:59:17Z", 342 "links": [ 343 { 344 "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", 345 "rel": "self" 346 }, 347 { 348 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", 349 "rel": "resource" 350 }, 351 { 352 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", 353 "rel": "stack" 354 } 355 ], 356 "logical_resource_id": "hello_world", 357 "resource_status_reason": "state changed", 358 "resource_status": "CREATE_COMPLETE", 359 "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", 360 "id": "93940999-7d40-44ae-8de4-19624e7b8d18" 361 } 362 ] 363 }` 364 365 // HandleListResourceEventsSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events` 366 // on the test handler mux that responds with a `ListResourceEvents` response. 367 func HandleListResourceEventsSuccessfully(t *testing.T, output string) { 368 th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events", func(w http.ResponseWriter, r *http.Request) { 369 th.TestMethod(t, r, "GET") 370 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 371 th.TestHeader(t, r, "Accept", "application/json") 372 373 w.Header().Set("Content-Type", "application/json") 374 if err := r.ParseForm(); err != nil { 375 t.Errorf("Failed to parse request form %v", err) 376 } 377 marker := r.Form.Get("marker") 378 switch marker { 379 case "": 380 fmt.Fprint(w, output) 381 case "93940999-7d40-44ae-8de4-19624e7b8d18": 382 fmt.Fprint(w, `{"events":[]}`) 383 default: 384 t.Fatalf("Unexpected marker: [%s]", marker) 385 } 386 }) 387 } 388 389 // GetExpected represents the expected object from a Get request. 390 var GetExpected = &stackevents.Event{ 391 ResourceName: "hello_world", 392 Time: Timestamp2, 393 Links: []gophercloud.Link{ 394 { 395 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", 396 Rel: "self", 397 }, 398 { 399 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", 400 Rel: "resource", 401 }, 402 { 403 Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", 404 Rel: "stack", 405 }, 406 }, 407 LogicalResourceID: "hello_world", 408 ResourceStatusReason: "state changed", 409 ResourceStatus: "CREATE_COMPLETE", 410 PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", 411 ID: "93940999-7d40-44ae-8de4-19624e7b8d18", 412 } 413 414 // GetOutput represents the response body from a Get request. 415 const GetOutput = ` 416 { 417 "event":{ 418 "resource_name": "hello_world", 419 "event_time": "2018-06-26T07:59:17Z", 420 "links": [ 421 { 422 "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", 423 "rel": "self" 424 }, 425 { 426 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", 427 "rel": "resource" 428 }, 429 { 430 "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", 431 "rel": "stack" 432 } 433 ], 434 "logical_resource_id": "hello_world", 435 "resource_status_reason": "state changed", 436 "resource_status": "CREATE_COMPLETE", 437 "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", 438 "id": "93940999-7d40-44ae-8de4-19624e7b8d18" 439 } 440 }` 441 442 // HandleGetSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events/93940999-7d40-44ae-8de4-19624e7b8d18` 443 // on the test handler mux that responds with a `Get` response. 444 func HandleGetSuccessfully(t *testing.T, output string) { 445 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) { 446 th.TestMethod(t, r, "GET") 447 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 448 th.TestHeader(t, r, "Accept", "application/json") 449 450 w.Header().Set("Content-Type", "application/json") 451 w.WriteHeader(http.StatusOK) 452 fmt.Fprint(w, output) 453 }) 454 }