blob: 94f78db8df45111bba4074c2b15edea5a6c244fe [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
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02008 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/orchestration/v1/buildinfo"
9 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
10 fake "gerrit.mcp.mirantis.net/debian/gophercloud.git/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}