Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame^] | 1 | // +build fixtures |
| 2 | |
Jon Perritt | efe6d1f | 2015-02-09 12:04:06 -0700 | [diff] [blame] | 3 | package buildinfo |
| 4 | |
| 5 | import ( |
| 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. |
| 15 | var 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. |
| 25 | const 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. |
| 37 | func 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 | } |