blob: bd986f3ef66b63b2062616deb310a560b4bc9743 [file] [log] [blame]
Jamie Hannafordb2a59c52015-02-17 14:56:17 +01001package fixture
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02008 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
9 "gerrit.mcp.mirantis.net/debian/gophercloud.git/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}