github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/providers/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/providers"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  	"github.com/gophercloud/gophercloud/testhelper/client"
    11  )
    12  
    13  // ProvidersListBody contains the canned body of a provider list response.
    14  const ProvidersListBody = `
    15  {
    16  	"providers":[
    17  	         {
    18  			"name": "amphora",
    19  			"description": "The Octavia Amphora driver."
    20  		},
    21  		{
    22  			"name": "ovn",
    23  			"description": "The Octavia OVN driver"
    24  		}
    25  	]
    26  }
    27  `
    28  
    29  var (
    30  	ProviderAmphora = providers.Provider{
    31  		Name:        "amphora",
    32  		Description: "The Octavia Amphora driver.",
    33  	}
    34  	ProviderOVN = providers.Provider{
    35  		Name:        "ovn",
    36  		Description: "The Octavia OVN driver",
    37  	}
    38  )
    39  
    40  // HandleProviderListSuccessfully sets up the test server to respond to a provider List request.
    41  func HandleProviderListSuccessfully(t *testing.T) {
    42  	th.Mux.HandleFunc("/v2.0/lbaas/providers", func(w http.ResponseWriter, r *http.Request) {
    43  		th.TestMethod(t, r, "GET")
    44  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    45  
    46  		w.Header().Add("Content-Type", "application/json")
    47  		r.ParseForm()
    48  		marker := r.Form.Get("marker")
    49  		switch marker {
    50  		case "":
    51  			fmt.Fprintf(w, ProvidersListBody)
    52  		default:
    53  			t.Fatalf("/v2.0/lbaas/providers invoked with unexpected marker=[%s]", marker)
    54  		}
    55  	})
    56  }