blob: f95d89301f44400c8c6e8c4d9628e846d93ff3ee [file] [log] [blame]
Jon Perritt9a9c3862015-01-19 17:16:22 -07001package base
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perritt9a9c3862015-01-19 17:16:22 -070010)
11
12// HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux
13// that responds with a `Get` response.
14func 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.
47func 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 Perritt9a9c3862015-01-19 17:16:22 -070051 w.WriteHeader(http.StatusNoContent)
52 })
53}