blob: fe98c86f99e0b692260e175cdf06b549cc77dff4 [file] [log] [blame]
Jamie Hannafordb2a59c52015-02-17 14:56:17 +01001package fixture
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 "github.com/gophercloud/gophercloud/testhelper/client"
Jamie Hannafordb2a59c52015-02-17 14:56:17 +010010)
11
12func SetupHandler(t *testing.T, url, method, requestBody, responseBody string, status int) {
13 th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
14 th.TestMethod(t, r, method)
15 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
16
17 if requestBody != "" {
18 th.TestJSONRequest(t, r, requestBody)
19 }
20
21 if responseBody != "" {
22 w.Header().Add("Content-Type", "application/json")
23 }
24
25 w.WriteHeader(status)
26
27 if responseBody != "" {
28 fmt.Fprintf(w, responseBody)
29 }
30 })
31}