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