blob: c240d5f5811e25b15d17384993bb383e3c2f109a [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Jon Perrittefe6d1f2015-02-09 12:04:06 -07002
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
jrperritt3d966162016-06-06 14:08:54 -05008 "github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo"
Jon Perritt27249f42016-02-18 10:35:59 -06009 th "github.com/gophercloud/gophercloud/testhelper"
10 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perrittefe6d1f2015-02-09 12:04:06 -070011)
12
13// GetExpected represents the expected object from a Get request.
jrperritt3d966162016-06-06 14:08:54 -050014var GetExpected = &buildinfo.BuildInfo{
15 API: buildinfo.Revision{
Jon Perrittefe6d1f2015-02-09 12:04:06 -070016 Revision: "2.4.5",
17 },
jrperritt3d966162016-06-06 14:08:54 -050018 Engine: buildinfo.Revision{
Jon Perrittefe6d1f2015-02-09 12:04:06 -070019 Revision: "1.2.1",
20 },
21}
22
23// GetOutput represents the response body from a Get request.
24const 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.
36func 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}