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