github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/loadbalancers/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/openstack/loadbalancer/v2/l7policies" 10 "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" 11 "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" 12 "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" 13 "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" 14 th "github.com/gophercloud/gophercloud/testhelper" 15 "github.com/gophercloud/gophercloud/testhelper/client" 16 ) 17 18 // LoadbalancersListBody contains the canned body of a loadbalancer list response. 19 const LoadbalancersListBody = ` 20 { 21 "loadbalancers":[ 22 { 23 "id": "c331058c-6a40-4144-948e-b9fb1df9db4b", 24 "project_id": "54030507-44f7-473c-9342-b4d14a95f692", 25 "created_at": "2019-06-30T04:15:37", 26 "updated_at": "2019-06-30T05:18:49", 27 "name": "web_lb", 28 "description": "lb config for the web tier", 29 "vip_subnet_id": "8a49c438-848f-467b-9655-ea1548708154", 30 "vip_address": "10.30.176.47", 31 "vip_port_id": "2a22e552-a347-44fd-b530-1f2b1b2a6735", 32 "flavor_id": "60df399a-ee85-11e9-81b4-2a2ae2dbcce4", 33 "provider": "haproxy", 34 "admin_state_up": true, 35 "provisioning_status": "ACTIVE", 36 "operating_status": "ONLINE", 37 "tags": ["test", "stage"] 38 }, 39 { 40 "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 41 "project_id": "54030507-44f7-473c-9342-b4d14a95f692", 42 "created_at": "2019-06-30T04:15:37", 43 "updated_at": "2019-06-30T05:18:49", 44 "name": "db_lb", 45 "description": "lb config for the db tier", 46 "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", 47 "vip_address": "10.30.176.48", 48 "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", 49 "flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 50 "availability_zone": "db_az", 51 "provider": "haproxy", 52 "admin_state_up": true, 53 "provisioning_status": "PENDING_CREATE", 54 "operating_status": "OFFLINE", 55 "tags": ["test", "stage"] 56 } 57 ] 58 } 59 ` 60 61 // SingleLoadbalancerBody is the canned body of a Get request on an existing loadbalancer. 62 const SingleLoadbalancerBody = ` 63 { 64 "loadbalancer": { 65 "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 66 "project_id": "54030507-44f7-473c-9342-b4d14a95f692", 67 "created_at": "2019-06-30T04:15:37", 68 "updated_at": "2019-06-30T05:18:49", 69 "name": "db_lb", 70 "description": "lb config for the db tier", 71 "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", 72 "vip_address": "10.30.176.48", 73 "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", 74 "flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 75 "availability_zone": "db_az", 76 "provider": "haproxy", 77 "admin_state_up": true, 78 "provisioning_status": "PENDING_CREATE", 79 "operating_status": "OFFLINE", 80 "tags": ["test", "stage"] 81 } 82 } 83 ` 84 85 // PostUpdateLoadbalancerBody is the canned response body of a Update request on an existing loadbalancer. 86 const PostUpdateLoadbalancerBody = ` 87 { 88 "loadbalancer": { 89 "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 90 "project_id": "54030507-44f7-473c-9342-b4d14a95f692", 91 "created_at": "2019-06-30T04:15:37", 92 "updated_at": "2019-06-30T05:18:49", 93 "name": "NewLoadbalancerName", 94 "description": "lb config for the db tier", 95 "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", 96 "vip_address": "10.30.176.48", 97 "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", 98 "flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 99 "provider": "haproxy", 100 "admin_state_up": true, 101 "provisioning_status": "PENDING_CREATE", 102 "operating_status": "OFFLINE", 103 "tags": ["test"] 104 } 105 } 106 ` 107 108 // PostFullyPopulatedLoadbalancerBody is the canned response body of a Create request of an fully populated loadbalancer. 109 const PostFullyPopulatedLoadbalancerBody = ` 110 { 111 "loadbalancer": { 112 "description": "My favorite load balancer", 113 "admin_state_up": true, 114 "project_id": "e3cd678b11784734bc366148aa37580e", 115 "provisioning_status": "ACTIVE", 116 "flavor_id": "", 117 "created_at": "2019-06-30T04:15:37", 118 "updated_at": "2019-06-30T05:18:49", 119 "listeners": [{ 120 "l7policies": [{ 121 "description": "", 122 "admin_state_up": true, 123 "rules": [], 124 "project_id": "e3cd678b11784734bc366148aa37580e", 125 "listener_id": "95de30ec-67f4-437b-b3f3-22c5d9ef9828", 126 "redirect_url": "https://www.example.com/", 127 "action": "REDIRECT_TO_URL", 128 "position": 1, 129 "id": "d0553837-f890-4981-b99a-f7cbd6a76577", 130 "name": "redirect_policy" 131 }], 132 "protocol": "HTTP", 133 "description": "", 134 "default_tls_container_ref": null, 135 "admin_state_up": true, 136 "default_pool_id": "c8cec227-410a-4a5b-af13-ecf38c2b0abb", 137 "project_id": "e3cd678b11784734bc366148aa37580e", 138 "default_tls_container_id": null, 139 "connection_limit": -1, 140 "sni_container_refs": [], 141 "protocol_port": 8080, 142 "id": "95de30ec-67f4-437b-b3f3-22c5d9ef9828", 143 "name": "redirect_listener" 144 }], 145 "vip_address": "203.0.113.50", 146 "vip_network_id": "d0d217df-3958-4fbf-a3c2-8dad2908c709", 147 "vip_subnet_id": "d4af86e1-0051-488c-b7a0-527f97490c9a", 148 "vip_port_id": "b4ca07d1-a31e-43e2-891a-7d14f419f342", 149 "provider": "octavia", 150 "pools": [{ 151 "lb_algorithm": "ROUND_ROBIN", 152 "protocol": "HTTP", 153 "description": "", 154 "admin_state_up": true, 155 "project_id": "e3cd678b11784734bc366148aa37580e", 156 "session_persistence": null, 157 "healthmonitor": { 158 "name": "", 159 "admin_state_up": true, 160 "project_id": "e3cd678b11784734bc366148aa37580e", 161 "delay": 3, 162 "expected_codes": "200,201,202", 163 "max_retries": 2, 164 "http_method": "GET", 165 "timeout": 1, 166 "max_retries_down": 3, 167 "url_path": "/index.html", 168 "type": "HTTP", 169 "id": "a8a2aa3f-d099-4752-8265-e6472f8147f9" 170 }, 171 "members": [{ 172 "name": "", 173 "weight": 1, 174 "admin_state_up": true, 175 "subnet_id": "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa", 176 "project_id": "e3cd678b11784734bc366148aa37580e", 177 "address": "192.0.2.16", 178 "protocol_port": 80, 179 "id": "7d19ad6c-d549-453e-a5cd-05382c6be96a" 180 },{ 181 "name": "", 182 "weight": 1, 183 "admin_state_up": true, 184 "subnet_id": "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa", 185 "project_id": "e3cd678b11784734bc366148aa37580e", 186 "address": "192.0.2.19", 187 "protocol_port": 80, 188 "id": "a167402b-caa6-41d5-b4d4-bde7f2cbfa5e" 189 }], 190 "id": "c8cec227-410a-4a5b-af13-ecf38c2b0abb", 191 "name": "rr_pool" 192 }], 193 "id": "607226db-27ef-4d41-ae89-f2a800e9c2db", 194 "operating_status": "ONLINE", 195 "name": "best_load_balancer", 196 "availability_zone": "my_az", 197 "tags": ["test_tag"] 198 } 199 } 200 ` 201 202 // GetLoadbalancerStatusesBody is the canned request body of a Get request on loadbalancer's status. 203 const GetLoadbalancerStatusesBody = ` 204 { 205 "statuses" : { 206 "loadbalancer": { 207 "id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 208 "name": "db_lb", 209 "provisioning_status": "PENDING_UPDATE", 210 "operating_status": "ACTIVE", 211 "tags": ["test", "stage"], 212 "listeners": [{ 213 "id": "db902c0c-d5ff-4753-b465-668ad9656918", 214 "name": "db", 215 "provisioning_status": "ACTIVE", 216 "pools": [{ 217 "id": "fad389a3-9a4a-4762-a365-8c7038508b5d", 218 "name": "db", 219 "provisioning_status": "ACTIVE", 220 "healthmonitor": { 221 "id": "67306cda-815d-4354-9fe4-59e09da9c3c5", 222 "type":"PING", 223 "provisioning_status": "ACTIVE" 224 }, 225 "members":[{ 226 "id": "2a280670-c202-4b0b-a562-34077415aabf", 227 "name": "db", 228 "address": "10.0.2.11", 229 "protocol_port": 80, 230 "provisioning_status": "ACTIVE" 231 }] 232 }] 233 }] 234 } 235 } 236 } 237 ` 238 239 // LoadbalancerStatsTree is the canned request body of a Get request on loadbalancer's statistics. 240 const GetLoadbalancerStatsBody = ` 241 { 242 "stats": { 243 "active_connections": 0, 244 "bytes_in": 9532, 245 "bytes_out": 22033, 246 "request_errors": 46, 247 "total_connections": 112 248 } 249 } 250 ` 251 252 var createdTime, _ = time.Parse(time.RFC3339, "2019-06-30T04:15:37Z") 253 var updatedTime, _ = time.Parse(time.RFC3339, "2019-06-30T05:18:49Z") 254 255 var ( 256 LoadbalancerWeb = loadbalancers.LoadBalancer{ 257 ID: "c331058c-6a40-4144-948e-b9fb1df9db4b", 258 ProjectID: "54030507-44f7-473c-9342-b4d14a95f692", 259 CreatedAt: createdTime, 260 UpdatedAt: updatedTime, 261 Name: "web_lb", 262 Description: "lb config for the web tier", 263 VipSubnetID: "8a49c438-848f-467b-9655-ea1548708154", 264 VipAddress: "10.30.176.47", 265 VipPortID: "2a22e552-a347-44fd-b530-1f2b1b2a6735", 266 FlavorID: "60df399a-ee85-11e9-81b4-2a2ae2dbcce4", 267 Provider: "haproxy", 268 AdminStateUp: true, 269 ProvisioningStatus: "ACTIVE", 270 OperatingStatus: "ONLINE", 271 Tags: []string{"test", "stage"}, 272 } 273 LoadbalancerDb = loadbalancers.LoadBalancer{ 274 ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 275 ProjectID: "54030507-44f7-473c-9342-b4d14a95f692", 276 CreatedAt: createdTime, 277 UpdatedAt: updatedTime, 278 Name: "db_lb", 279 Description: "lb config for the db tier", 280 VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", 281 VipAddress: "10.30.176.48", 282 VipPortID: "2bf413c8-41a9-4477-b505-333d5cbe8b55", 283 FlavorID: "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 284 AvailabilityZone: "db_az", 285 Provider: "haproxy", 286 AdminStateUp: true, 287 ProvisioningStatus: "PENDING_CREATE", 288 OperatingStatus: "OFFLINE", 289 Tags: []string{"test", "stage"}, 290 } 291 LoadbalancerUpdated = loadbalancers.LoadBalancer{ 292 ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 293 ProjectID: "54030507-44f7-473c-9342-b4d14a95f692", 294 CreatedAt: createdTime, 295 UpdatedAt: updatedTime, 296 Name: "NewLoadbalancerName", 297 Description: "lb config for the db tier", 298 VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086", 299 VipAddress: "10.30.176.48", 300 VipPortID: "2bf413c8-41a9-4477-b505-333d5cbe8b55", 301 FlavorID: "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 302 Provider: "haproxy", 303 AdminStateUp: true, 304 ProvisioningStatus: "PENDING_CREATE", 305 OperatingStatus: "OFFLINE", 306 Tags: []string{"test"}, 307 } 308 FullyPopulatedLoadBalancerDb = loadbalancers.LoadBalancer{ 309 Description: "My favorite load balancer", 310 AdminStateUp: true, 311 ProjectID: "e3cd678b11784734bc366148aa37580e", 312 UpdatedAt: updatedTime, 313 CreatedAt: createdTime, 314 ProvisioningStatus: "ACTIVE", 315 VipSubnetID: "d4af86e1-0051-488c-b7a0-527f97490c9a", 316 VipNetworkID: "d0d217df-3958-4fbf-a3c2-8dad2908c709", 317 VipAddress: "203.0.113.50", 318 VipPortID: "b4ca07d1-a31e-43e2-891a-7d14f419f342", 319 AvailabilityZone: "my_az", 320 ID: "607226db-27ef-4d41-ae89-f2a800e9c2db", 321 OperatingStatus: "ONLINE", 322 Name: "best_load_balancer", 323 FlavorID: "", 324 Provider: "octavia", 325 Tags: []string{"test_tag"}, 326 Listeners: []listeners.Listener{{ 327 ID: "95de30ec-67f4-437b-b3f3-22c5d9ef9828", 328 ProjectID: "e3cd678b11784734bc366148aa37580e", 329 Name: "redirect_listener", 330 Description: "", 331 Protocol: "HTTP", 332 ProtocolPort: 8080, 333 DefaultPoolID: "c8cec227-410a-4a5b-af13-ecf38c2b0abb", 334 AdminStateUp: true, 335 ConnLimit: -1, 336 SniContainerRefs: []string{}, 337 L7Policies: []l7policies.L7Policy{{ 338 ID: "d0553837-f890-4981-b99a-f7cbd6a76577", 339 Name: "redirect_policy", 340 ListenerID: "95de30ec-67f4-437b-b3f3-22c5d9ef9828", 341 ProjectID: "e3cd678b11784734bc366148aa37580e", 342 Description: "", 343 Action: "REDIRECT_TO_URL", 344 Position: 1, 345 RedirectURL: "https://www.example.com/", 346 AdminStateUp: true, 347 Rules: []l7policies.Rule{}, 348 }}, 349 }}, 350 Pools: []pools.Pool{{ 351 LBMethod: "ROUND_ROBIN", 352 Protocol: "HTTP", 353 Description: "", 354 AdminStateUp: true, 355 Name: "rr_pool", 356 ID: "c8cec227-410a-4a5b-af13-ecf38c2b0abb", 357 ProjectID: "e3cd678b11784734bc366148aa37580e", 358 Members: []pools.Member{{ 359 Name: "", 360 Address: "192.0.2.16", 361 SubnetID: "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa", 362 AdminStateUp: true, 363 ProtocolPort: 80, 364 ID: "7d19ad6c-d549-453e-a5cd-05382c6be96a", 365 ProjectID: "e3cd678b11784734bc366148aa37580e", 366 Weight: 1, 367 }, { 368 Name: "", 369 Address: "192.0.2.19", 370 SubnetID: "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa", 371 AdminStateUp: true, 372 ProtocolPort: 80, 373 ID: "a167402b-caa6-41d5-b4d4-bde7f2cbfa5e", 374 ProjectID: "e3cd678b11784734bc366148aa37580e", 375 Weight: 1, 376 }}, 377 Monitor: monitors.Monitor{ 378 ID: "a8a2aa3f-d099-4752-8265-e6472f8147f9", 379 ProjectID: "e3cd678b11784734bc366148aa37580e", 380 Name: "", 381 Type: "HTTP", 382 Timeout: 1, 383 MaxRetries: 2, 384 Delay: 3, 385 MaxRetriesDown: 3, 386 HTTPMethod: "GET", 387 URLPath: "/index.html", 388 ExpectedCodes: "200,201,202", 389 AdminStateUp: true, 390 }, 391 }}, 392 } 393 LoadbalancerStatusesTree = loadbalancers.StatusTree{ 394 Loadbalancer: &loadbalancers.LoadBalancer{ 395 ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 396 Name: "db_lb", 397 ProvisioningStatus: "PENDING_UPDATE", 398 OperatingStatus: "ACTIVE", 399 Tags: []string{"test", "stage"}, 400 Listeners: []listeners.Listener{{ 401 ID: "db902c0c-d5ff-4753-b465-668ad9656918", 402 Name: "db", 403 ProvisioningStatus: "ACTIVE", 404 Pools: []pools.Pool{{ 405 ID: "fad389a3-9a4a-4762-a365-8c7038508b5d", 406 Name: "db", 407 ProvisioningStatus: "ACTIVE", 408 Monitor: monitors.Monitor{ 409 ID: "67306cda-815d-4354-9fe4-59e09da9c3c5", 410 Type: "PING", 411 ProvisioningStatus: "ACTIVE", 412 }, 413 Members: []pools.Member{{ 414 ID: "2a280670-c202-4b0b-a562-34077415aabf", 415 Name: "db", 416 Address: "10.0.2.11", 417 ProtocolPort: 80, 418 ProvisioningStatus: "ACTIVE", 419 }}, 420 }}, 421 }}, 422 }, 423 } 424 LoadbalancerStatsTree = loadbalancers.Stats{ 425 ActiveConnections: 0, 426 BytesIn: 9532, 427 BytesOut: 22033, 428 RequestErrors: 46, 429 TotalConnections: 112, 430 } 431 ) 432 433 // HandleLoadbalancerListSuccessfully sets up the test server to respond to a loadbalancer List request. 434 func HandleLoadbalancerListSuccessfully(t *testing.T) { 435 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) { 436 th.TestMethod(t, r, "GET") 437 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 438 439 w.Header().Add("Content-Type", "application/json") 440 r.ParseForm() 441 marker := r.Form.Get("marker") 442 switch marker { 443 case "": 444 fmt.Fprintf(w, LoadbalancersListBody) 445 case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab": 446 fmt.Fprintf(w, `{ "loadbalancers": [] }`) 447 default: 448 t.Fatalf("/v2.0/lbaas/loadbalancers invoked with unexpected marker=[%s]", marker) 449 } 450 }) 451 } 452 453 // HandleFullyPopulatedLoadbalancerCreationSuccessfully sets up the test server to respond to a 454 // fully populated loadbalancer creation request with a given response. 455 func HandleFullyPopulatedLoadbalancerCreationSuccessfully(t *testing.T, response string) { 456 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) { 457 th.TestMethod(t, r, "POST") 458 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 459 th.TestJSONRequest(t, r, `{ 460 "loadbalancer": { 461 "admin_state_up": true, 462 "flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 463 "listeners": [ 464 { 465 "default_pool": { 466 "healthmonitor": { 467 "delay": 3, 468 "expected_codes": "200", 469 "http_method": "GET", 470 "max_retries": 2, 471 "max_retries_down": 3, 472 "name": "db", 473 "timeout": 1, 474 "type": "HTTP", 475 "url_path": "/index.html" 476 }, 477 "lb_algorithm": "ROUND_ROBIN", 478 "members": [ 479 { 480 "address": "192.0.2.51", 481 "protocol_port": 80 482 }, 483 { 484 "address": "192.0.2.52", 485 "protocol_port": 80 486 } 487 ], 488 "name": "Example pool", 489 "protocol": "HTTP" 490 }, 491 "l7policies": [ 492 { 493 "action": "REDIRECT_TO_URL", 494 "name": "redirect-example.com", 495 "redirect_url": "http://www.example.com", 496 "rules": [ 497 { 498 "compare_type": "REGEX", 499 "type": "PATH", 500 "value": "/images*" 501 } 502 ] 503 } 504 ], 505 "name": "redirect_listener", 506 "protocol": "HTTP", 507 "protocol_port": 8080 508 } 509 ], 510 "name": "db_lb", 511 "provider": "octavia", 512 "tags": [ 513 "test", 514 "stage" 515 ], 516 "vip_address": "10.30.176.48", 517 "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", 518 "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086" 519 } 520 }`) 521 522 w.WriteHeader(http.StatusAccepted) 523 w.Header().Add("Content-Type", "application/json") 524 fmt.Fprintf(w, response) 525 }) 526 } 527 528 // HandleLoadbalancerCreationSuccessfully sets up the test server to respond to a loadbalancer creation request 529 // with a given response. 530 func HandleLoadbalancerCreationSuccessfully(t *testing.T, response string) { 531 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) { 532 th.TestMethod(t, r, "POST") 533 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 534 th.TestJSONRequest(t, r, `{ 535 "loadbalancer": { 536 "name": "db_lb", 537 "vip_port_id": "2bf413c8-41a9-4477-b505-333d5cbe8b55", 538 "vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086", 539 "vip_address": "10.30.176.48", 540 "flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4", 541 "provider": "haproxy", 542 "admin_state_up": true, 543 "tags": ["test", "stage"] 544 } 545 }`) 546 547 w.WriteHeader(http.StatusAccepted) 548 w.Header().Add("Content-Type", "application/json") 549 fmt.Fprintf(w, response) 550 }) 551 } 552 553 // HandleLoadbalancerGetSuccessfully sets up the test server to respond to a loadbalancer Get request. 554 func HandleLoadbalancerGetSuccessfully(t *testing.T) { 555 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) { 556 th.TestMethod(t, r, "GET") 557 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 558 th.TestHeader(t, r, "Accept", "application/json") 559 560 fmt.Fprintf(w, SingleLoadbalancerBody) 561 }) 562 } 563 564 // HandleLoadbalancerGetStatusesTree sets up the test server to respond to a loadbalancer Get statuses tree request. 565 func HandleLoadbalancerGetStatusesTree(t *testing.T) { 566 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/status", func(w http.ResponseWriter, r *http.Request) { 567 th.TestMethod(t, r, "GET") 568 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 569 th.TestHeader(t, r, "Accept", "application/json") 570 571 fmt.Fprintf(w, GetLoadbalancerStatusesBody) 572 }) 573 } 574 575 // HandleLoadbalancerDeletionSuccessfully sets up the test server to respond to a loadbalancer deletion request. 576 func HandleLoadbalancerDeletionSuccessfully(t *testing.T) { 577 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) { 578 th.TestMethod(t, r, "DELETE") 579 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 580 581 w.WriteHeader(http.StatusNoContent) 582 }) 583 } 584 585 // HandleLoadbalancerUpdateSuccessfully sets up the test server to respond to a loadbalancer Update request. 586 func HandleLoadbalancerUpdateSuccessfully(t *testing.T) { 587 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) { 588 th.TestMethod(t, r, "PUT") 589 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 590 th.TestHeader(t, r, "Accept", "application/json") 591 th.TestHeader(t, r, "Content-Type", "application/json") 592 th.TestJSONRequest(t, r, `{ 593 "loadbalancer": { 594 "name": "NewLoadbalancerName", 595 "tags": ["test"] 596 } 597 }`) 598 599 fmt.Fprintf(w, PostUpdateLoadbalancerBody) 600 }) 601 } 602 603 // HandleLoadbalancerGetStatsTree sets up the test server to respond to a loadbalancer Get stats tree request. 604 func HandleLoadbalancerGetStatsTree(t *testing.T) { 605 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/stats", func(w http.ResponseWriter, r *http.Request) { 606 th.TestMethod(t, r, "GET") 607 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 608 th.TestHeader(t, r, "Accept", "application/json") 609 610 fmt.Fprintf(w, GetLoadbalancerStatsBody) 611 }) 612 } 613 614 // HandleLoadbalancerFailoverSuccessfully sets up the test server to respond to a loadbalancer failover request. 615 func HandleLoadbalancerFailoverSuccessfully(t *testing.T) { 616 th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/failover", func(w http.ResponseWriter, r *http.Request) { 617 th.TestMethod(t, r, "PUT") 618 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 619 620 w.WriteHeader(http.StatusAccepted) 621 }) 622 }