jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 1 | package testing |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 2 | |
| 3 | import ( |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 7 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 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) { |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 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) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 18 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 19 | w.Header().Set("Content-Type", "application/json") |
| 20 | w.WriteHeader(http.StatusOK) |
| 21 | fmt.Fprintf(w, ` |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 22 | { |
| 23 | "flavors": [ |
| 24 | { |
| 25 | "id": "europe", |
| 26 | "providers": [ |
| 27 | { |
| 28 | "provider": "Fastly", |
| 29 | "links": [ |
| 30 | { |
Jon Perritt | 1e5e293 | 2015-01-27 12:13:19 -0700 | [diff] [blame] | 31 | "href": "http://www.fastly.com", |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 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 | `) |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 47 | }) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 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) { |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 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) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 56 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 57 | w.Header().Set("Content-Type", "application/json") |
| 58 | w.WriteHeader(http.StatusOK) |
| 59 | fmt.Fprintf(w, ` |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 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 | `) |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 81 | }) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 82 | } |