blob: 166b2c8b30eb797324763a14436f3c3f38673a46 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jon Perrittfbcb0ba2015-01-20 19:53:01 -07003package flavors
4
5import (
Jon Perrittd3416092015-03-27 10:36:34 -06006 "fmt"
7 "net/http"
8 "testing"
Jon Perrittfbcb0ba2015-01-20 19:53:01 -07009
Jon Perrittd3416092015-03-27 10:36:34 -060010 th "github.com/rackspace/gophercloud/testhelper"
11 fake "github.com/rackspace/gophercloud/testhelper/client"
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070012)
13
14// HandleListCDNFlavorsSuccessfully creates an HTTP handler at `/flavors` on the test handler mux
15// that responds with a `List` response.
16func HandleListCDNFlavorsSuccessfully(t *testing.T) {
Jon Perrittd3416092015-03-27 10:36:34 -060017 th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) {
18 th.TestMethod(t, r, "GET")
19 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070020
Jon Perrittd3416092015-03-27 10:36:34 -060021 w.Header().Set("Content-Type", "application/json")
22 w.WriteHeader(http.StatusOK)
23 fmt.Fprintf(w, `
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070024 {
25 "flavors": [
26 {
27 "id": "europe",
28 "providers": [
29 {
30 "provider": "Fastly",
31 "links": [
32 {
Jon Perritt1e5e2932015-01-27 12:13:19 -070033 "href": "http://www.fastly.com",
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070034 "rel": "provider_url"
35 }
36 ]
37 }
38 ],
39 "links": [
40 {
41 "href": "https://www.poppycdn.io/v1.0/flavors/europe",
42 "rel": "self"
43 }
44 ]
45 }
46 ]
47 }
48 `)
Jon Perrittd3416092015-03-27 10:36:34 -060049 })
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070050}
51
52// HandleGetCDNFlavorSuccessfully creates an HTTP handler at `/flavors/{id}` on the test handler mux
53// that responds with a `Get` response.
54func HandleGetCDNFlavorSuccessfully(t *testing.T) {
Jon Perrittd3416092015-03-27 10:36:34 -060055 th.Mux.HandleFunc("/flavors/asia", func(w http.ResponseWriter, r *http.Request) {
56 th.TestMethod(t, r, "GET")
57 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070058
Jon Perrittd3416092015-03-27 10:36:34 -060059 w.Header().Set("Content-Type", "application/json")
60 w.WriteHeader(http.StatusOK)
61 fmt.Fprintf(w, `
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070062 {
63 "id" : "asia",
64 "providers" : [
65 {
66 "provider" : "ChinaCache",
67 "links": [
68 {
69 "href": "http://www.chinacache.com",
70 "rel": "provider_url"
71 }
72 ]
73 }
74 ],
75 "links": [
76 {
77 "href": "https://www.poppycdn.io/v1.0/flavors/asia",
78 "rel": "self"
79 }
80 ]
81 }
82 `)
Jon Perrittd3416092015-03-27 10:36:34 -060083 })
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070084}