Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Jon Perritt | 9a9c386 | 2015-01-19 17:16:22 -0700 | [diff] [blame] | 3 | package base |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "testing" |
| 9 | |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 12 | ) |
| 13 | |
| 14 | // HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux |
| 15 | // that responds with a `Get` response. |
| 16 | func HandleGetSuccessfully(t *testing.T) { |
| 17 | th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 18 | th.TestMethod(t, r, "GET") |
| 19 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 20 | th.TestHeader(t, r, "Accept", "application/json") |
| 21 | w.WriteHeader(http.StatusOK) |
| 22 | fmt.Fprintf(w, ` |
| 23 | { |
| 24 | "resources": { |
| 25 | "rel/cdn": { |
| 26 | "href-template": "services{?marker,limit}", |
| 27 | "href-vars": { |
| 28 | "marker": "param/marker", |
| 29 | "limit": "param/limit" |
| 30 | }, |
| 31 | "hints": { |
| 32 | "allow": [ |
| 33 | "GET" |
| 34 | ], |
| 35 | "formats": { |
| 36 | "application/json": {} |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | `) |
| 43 | |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | // HandlePingSuccessfully creates an HTTP handler at `/ping` on the test handler |
| 48 | // mux that responds with a `Ping` response. |
| 49 | func HandlePingSuccessfully(t *testing.T) { |
| 50 | th.Mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) { |
| 51 | th.TestMethod(t, r, "GET") |
| 52 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jon Perritt | 9a9c386 | 2015-01-19 17:16:22 -0700 | [diff] [blame] | 53 | w.WriteHeader(http.StatusNoContent) |
| 54 | }) |
| 55 | } |