blob: 55680748613724b051650abc37edcc4b7a8bbd54 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jon Perritt9a9c3862015-01-19 17:16:22 -07003package base
4
5import (
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.
16func 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.
49func 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 Perritt9a9c3862015-01-19 17:16:22 -070053 w.WriteHeader(http.StatusNoContent)
54 })
55}