blob: 285075efb662910d2913d57b1bfdd78e9b81390c [file] [log] [blame]
Jon Perrittfbcb0ba2015-01-20 19:53:01 -07001package flavors
2
3import (
Jon Perrittd3416092015-03-27 10:36:34 -06004 "fmt"
5 "net/http"
6 "testing"
Jon Perrittfbcb0ba2015-01-20 19:53:01 -07007
Jon Perritt27249f42016-02-18 10:35:59 -06008 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070010)
11
12// HandleListCDNFlavorsSuccessfully creates an HTTP handler at `/flavors` on the test handler mux
13// that responds with a `List` response.
14func HandleListCDNFlavorsSuccessfully(t *testing.T) {
Jon Perrittd3416092015-03-27 10:36:34 -060015 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)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070018
Jon Perrittd3416092015-03-27 10:36:34 -060019 w.Header().Set("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21 fmt.Fprintf(w, `
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070022 {
23 "flavors": [
24 {
25 "id": "europe",
26 "providers": [
27 {
28 "provider": "Fastly",
29 "links": [
30 {
Jon Perritt1e5e2932015-01-27 12:13:19 -070031 "href": "http://www.fastly.com",
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070032 "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 `)
Jon Perrittd3416092015-03-27 10:36:34 -060047 })
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070048}
49
50// HandleGetCDNFlavorSuccessfully creates an HTTP handler at `/flavors/{id}` on the test handler mux
51// that responds with a `Get` response.
52func HandleGetCDNFlavorSuccessfully(t *testing.T) {
Jon Perrittd3416092015-03-27 10:36:34 -060053 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)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070056
Jon Perrittd3416092015-03-27 10:36:34 -060057 w.Header().Set("Content-Type", "application/json")
58 w.WriteHeader(http.StatusOK)
59 fmt.Fprintf(w, `
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070060 {
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 `)
Jon Perrittd3416092015-03-27 10:36:34 -060081 })
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070082}