blob: d1240b8ba24386701e84283360b75e4013b96f6a [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jon Perrittefe6d1f2015-02-09 12:04:06 -07003package buildinfo
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// GetExpected represents the expected object from a Get request.
15var GetExpected = &BuildInfo{
16 API: Revision{
17 Revision: "2.4.5",
18 },
19 Engine: Revision{
20 Revision: "1.2.1",
21 },
22}
23
24// GetOutput represents the response body from a Get request.
25const GetOutput = `
26{
27 "api": {
28 "revision": "2.4.5"
29 },
30 "engine": {
31 "revision": "1.2.1"
32 }
33}`
34
35// HandleGetSuccessfully creates an HTTP handler at `/build_info`
36// on the test handler mux that responds with a `Get` response.
37func HandleGetSuccessfully(t *testing.T, output string) {
38 th.Mux.HandleFunc("/build_info", func(w http.ResponseWriter, r *http.Request) {
39 th.TestMethod(t, r, "GET")
40 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
41 th.TestHeader(t, r, "Accept", "application/json")
42
43 w.Header().Set("Content-Type", "application/json")
44 w.WriteHeader(http.StatusOK)
45 fmt.Fprintf(w, output)
46 })
47}