blob: 20ea09b4425aa9fc632f5586845ee243c0919b30 [file] [log] [blame]
Jon Perrittefe6d1f2015-02-09 12:04:06 -07001package buildinfo
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12// GetExpected represents the expected object from a Get request.
13var GetExpected = &BuildInfo{
14 API: Revision{
15 Revision: "2.4.5",
16 },
17 Engine: Revision{
18 Revision: "1.2.1",
19 },
20}
21
22// GetOutput represents the response body from a Get request.
23const GetOutput = `
24{
25 "api": {
26 "revision": "2.4.5"
27 },
28 "engine": {
29 "revision": "1.2.1"
30 }
31}`
32
33// HandleGetSuccessfully creates an HTTP handler at `/build_info`
34// on the test handler mux that responds with a `Get` response.
35func HandleGetSuccessfully(t *testing.T, output string) {
36 th.Mux.HandleFunc("/build_info", func(w http.ResponseWriter, r *http.Request) {
37 th.TestMethod(t, r, "GET")
38 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
39 th.TestHeader(t, r, "Accept", "application/json")
40
41 w.Header().Set("Content-Type", "application/json")
42 w.WriteHeader(http.StatusOK)
43 fmt.Fprintf(w, output)
44 })
45}