github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/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/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/providers"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/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  		if err := r.ParseForm(); err != nil {
    48  			t.Errorf("Failed to parse request form %v", err)
    49  		}
    50  		marker := r.Form.Get("marker")
    51  		switch marker {
    52  		case "":
    53  			fmt.Fprint(w, ProvidersListBody)
    54  		default:
    55  			t.Fatalf("/v2.0/lbaas/providers invoked with unexpected marker=[%s]", marker)
    56  		}
    57  	})
    58  }