github.com/gophercloud/gophercloud@v1.11.0/openstack/cdn/v1/flavors/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/gophercloud/gophercloud/testhelper" 9 fake "github.com/gophercloud/gophercloud/testhelper/client" 10 ) 11 12 // HandleListCDNFlavorsSuccessfully creates an HTTP handler at `/flavors` on the test handler mux 13 // that responds with a `List` response. 14 func HandleListCDNFlavorsSuccessfully(t *testing.T) { 15 th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) { 16 th.TestMethod(t, r, "GET") 17 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 18 19 w.Header().Set("Content-Type", "application/json") 20 w.WriteHeader(http.StatusOK) 21 fmt.Fprintf(w, ` 22 { 23 "flavors": [ 24 { 25 "id": "europe", 26 "providers": [ 27 { 28 "provider": "Fastly", 29 "links": [ 30 { 31 "href": "http://www.fastly.com", 32 "rel": "provider_url" 33 } 34 ] 35 } 36 ], 37 "links": [ 38 { 39 "href": "https://www.poppycdn.io/v1.0/flavors/europe", 40 "rel": "self" 41 } 42 ] 43 } 44 ] 45 } 46 `) 47 }) 48 } 49 50 // HandleGetCDNFlavorSuccessfully creates an HTTP handler at `/flavors/{id}` on the test handler mux 51 // that responds with a `Get` response. 52 func HandleGetCDNFlavorSuccessfully(t *testing.T) { 53 th.Mux.HandleFunc("/flavors/asia", func(w http.ResponseWriter, r *http.Request) { 54 th.TestMethod(t, r, "GET") 55 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 56 57 w.Header().Set("Content-Type", "application/json") 58 w.WriteHeader(http.StatusOK) 59 fmt.Fprintf(w, ` 60 { 61 "id" : "asia", 62 "providers" : [ 63 { 64 "provider" : "ChinaCache", 65 "links": [ 66 { 67 "href": "http://www.chinacache.com", 68 "rel": "provider_url" 69 } 70 ] 71 } 72 ], 73 "links": [ 74 { 75 "href": "https://www.poppycdn.io/v1.0/flavors/asia", 76 "rel": "self" 77 } 78 ] 79 } 80 `) 81 }) 82 }