github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/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/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/flavorprofiles" 9 10 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 11 "github.com/vnpaycloud-console/gophercloud/v2/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 if err := r.ParseForm(); err != nil { 92 t.Errorf("Failed to parse request form %v", err) 93 } 94 marker := r.Form.Get("marker") 95 switch marker { 96 case "": 97 fmt.Fprint(w, FlavorProfilesListBody) 98 case "3a0d060b-fcec-4250-9ab6-940b806a12dd": 99 fmt.Fprint(w, `{ "flavors": [] }`) 100 default: 101 t.Fatalf("/v2.0/lbaas/flavors invoked with unexpected marker=[%s]", marker) 102 } 103 }) 104 } 105 106 func HandleFlavorProfileCreationSuccessfully(t *testing.T, response string) { 107 th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles", func(w http.ResponseWriter, r *http.Request) { 108 th.TestMethod(t, r, "POST") 109 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 110 th.TestJSONRequest(t, r, `{ 111 "flavorprofile": { 112 "name": "amphora-test", 113 "provider_name": "amphora", 114 "flavor_data": "{\"loadbalancer_topology\": \"ACTIVE_STANDBY\"}" 115 } 116 }`) 117 118 w.WriteHeader(http.StatusAccepted) 119 w.Header().Add("Content-Type", "application/json") 120 fmt.Fprint(w, response) 121 }) 122 } 123 124 func HandleFlavorProfileGetSuccessfully(t *testing.T) { 125 th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles/dcd65be5-f117-4260-ab3d-b32cc5bd1272", func(w http.ResponseWriter, r *http.Request) { 126 th.TestMethod(t, r, "GET") 127 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 128 th.TestHeader(t, r, "Accept", "application/json") 129 130 fmt.Fprint(w, SingleFlavorProfileBody) 131 }) 132 } 133 134 func HandleFlavorProfileDeletionSuccessfully(t *testing.T) { 135 th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles/dcd65be5-f117-4260-ab3d-b32cc5bd1272", func(w http.ResponseWriter, r *http.Request) { 136 th.TestMethod(t, r, "DELETE") 137 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 138 139 w.WriteHeader(http.StatusNoContent) 140 }) 141 } 142 143 func HandleFlavorProfileUpdateSuccessfully(t *testing.T) { 144 th.Mux.HandleFunc("/v2.0/lbaas/flavorprofiles/dcd65be5-f117-4260-ab3d-b32cc5bd1272", func(w http.ResponseWriter, r *http.Request) { 145 th.TestMethod(t, r, "PUT") 146 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 147 th.TestHeader(t, r, "Accept", "application/json") 148 th.TestHeader(t, r, "Content-Type", "application/json") 149 th.TestJSONRequest(t, r, `{ 150 "flavorprofile": { 151 "name": "amphora-test-updated", 152 "provider_name": "amphora", 153 "flavor_data": "{\"loadbalancer_topology\": \"SINGLE\"}" 154 } 155 }`) 156 157 fmt.Fprint(w, PostUpdateFlavorBody) 158 }) 159 }