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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/flavorprofiles"
     9  
    10  	th "github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  const FlavorProfilesListBody = `
    15  {
    16  	"flavorprofiles": [
    17          {
    18              "id": "c55d080d-af45-47ee-b48c-4caa5e87724f",
    19              "name": "amphora-single",
    20              "provider_name": "amphora",
    21              "flavor_data": "{\"loadbalancer_topology\": \"SINGLE\"}"
    22          },
    23  		{
    24              "id": "f78d2815-3714-4b6e-91d8-cf821ba01017",
    25              "name": "amphora-act-stdby",
    26              "provider_name": "amphora",
    27              "flavor_data": "{\"loadbalancer_topology\": \"ACTIVE_STANDBY\"}"
    28          }
    29      ]
    30  }
    31  `
    32  
    33  const SingleFlavorProfileBody = `
    34  {
    35  	"flavorprofile": {
    36  		"id": "dcd65be5-f117-4260-ab3d-b32cc5bd1272",
    37  		"name": "amphora-test",
    38  		"provider_name": "amphora",
    39  		"flavor_data": "{\"loadbalancer_topology\": \"ACTIVE_STANDBY\"}"
    40  	}
    41  }
    42  `
    43  
    44  const PostUpdateFlavorBody = `
    45  {
    46  	"flavorprofile": {
    47  		"id": "dcd65be5-f117-4260-ab3d-b32cc5bd1272",
    48  		"name": "amphora-test-updated",
    49  		"provider_name": "amphora",
    50  		"flavor_data": "{\"loadbalancer_topology\": \"SINGLE\"}"
    51  	}
    52  }
    53  `
    54  
    55  var (
    56  	FlavorProfileSingle = flavorprofiles.FlavorProfile{
    57  		ID:           "c55d080d-af45-47ee-b48c-4caa5e87724f",
    58  		Name:         "amphora-single",
    59  		ProviderName: "amphora",
    60  		FlavorData:   "{\"loadbalancer_topology\": \"SINGLE\"}",
    61  	}
    62  
    63  	FlavorProfileAct = flavorprofiles.FlavorProfile{
    64  		ID:           "f78d2815-3714-4b6e-91d8-cf821ba01017",
    65  		Name:         "amphora-act-stdby",
    66  		ProviderName: "amphora",
    67  		FlavorData:   "{\"loadbalancer_topology\": \"ACTIVE_STANDBY\"}",
    68  	}
    69  
    70  	FlavorDb = flavorprofiles.FlavorProfile{
    71  		ID:           "dcd65be5-f117-4260-ab3d-b32cc5bd1272",
    72  		Name:         "amphora-test",
    73  		ProviderName: "amphora",
    74  		FlavorData:   "{\"loadbalancer_topology\": \"ACTIVE_STANDBY\"}",
    75  	}
    76  
    77  	FlavorUpdated = flavorprofiles.FlavorProfile{
    78  		ID:           "dcd65be5-f117-4260-ab3d-b32cc5bd1272",
    79  		Name:         "amphora-test-updated",
    80  		ProviderName: "amphora",
    81  		FlavorData:   "{\"loadbalancer_topology\": \"SINGLE\"}",
    82  	}
    83  )
    84  
    85  func HandleFlavorProfileListSuccessfully(t *testing.T) {
    86  	th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles", func(w http.ResponseWriter, r *http.Request) {
    87  		th.TestMethod(t, r, "GET")
    88  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    89  
    90  		w.Header().Add("Content-Type", "application/json")
    91  		r.ParseForm()
    92  		marker := r.Form.Get("marker")
    93  		switch marker {
    94  		case "":
    95  			fmt.Fprintf(w, FlavorProfilesListBody)
    96  		case "3a0d060b-fcec-4250-9ab6-940b806a12dd":
    97  			fmt.Fprintf(w, `{ "flavors": [] }`)
    98  		default:
    99  			t.Fatalf("/v2.0/lbaas/flavors invoked with unexpected marker=[%s]", marker)
   100  		}
   101  	})
   102  }
   103  
   104  func HandleFlavorProfileCreationSuccessfully(t *testing.T, response string) {
   105  	th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles", func(w http.ResponseWriter, r *http.Request) {
   106  		th.TestMethod(t, r, "POST")
   107  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   108  		th.TestJSONRequest(t, r, `{
   109  			"flavorprofile": {
   110  				"name": "amphora-test",
   111  				"provider_name": "amphora",
   112  				"flavor_data": "{\"loadbalancer_topology\": \"ACTIVE_STANDBY\"}"
   113  			}
   114  		}`)
   115  
   116  		w.WriteHeader(http.StatusAccepted)
   117  		w.Header().Add("Content-Type", "application/json")
   118  		fmt.Fprintf(w, response)
   119  	})
   120  }
   121  
   122  func HandleFlavorProfileGetSuccessfully(t *testing.T) {
   123  	th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles/dcd65be5-f117-4260-ab3d-b32cc5bd1272", func(w http.ResponseWriter, r *http.Request) {
   124  		th.TestMethod(t, r, "GET")
   125  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   126  		th.TestHeader(t, r, "Accept", "application/json")
   127  
   128  		fmt.Fprintf(w, SingleFlavorProfileBody)
   129  	})
   130  }
   131  
   132  func HandleFlavorProfileDeletionSuccessfully(t *testing.T) {
   133  	th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles/dcd65be5-f117-4260-ab3d-b32cc5bd1272", func(w http.ResponseWriter, r *http.Request) {
   134  		th.TestMethod(t, r, "DELETE")
   135  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   136  
   137  		w.WriteHeader(http.StatusNoContent)
   138  	})
   139  }
   140  
   141  func HandleFlavorProfileUpdateSuccessfully(t *testing.T) {
   142  	th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles/dcd65be5-f117-4260-ab3d-b32cc5bd1272", func(w http.ResponseWriter, r *http.Request) {
   143  		th.TestMethod(t, r, "PUT")
   144  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   145  		th.TestHeader(t, r, "Accept", "application/json")
   146  		th.TestHeader(t, r, "Content-Type", "application/json")
   147  		th.TestJSONRequest(t, r, `{
   148  			"flavorprofile": {
   149  				"name": "amphora-test-updated",
   150  				"provider_name": "amphora",
   151  				"flavor_data": "{\"loadbalancer_topology\": \"SINGLE\"}"
   152  			}
   153  		}`)
   154  
   155  		fmt.Fprintf(w, PostUpdateFlavorBody)
   156  	})
   157  }