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