blob: 0ed7de9f1d7bc10e68f3ea600ceb5a0f91b11d5c [file] [log] [blame]
Ash Wilsonce942a82014-10-13 11:48:01 -04001// +build fixtures
2
3package extensions
4
5import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 th "github.com/rackspace/gophercloud/testhelper"
11 "github.com/rackspace/gophercloud/testhelper/client"
12)
13
14// ListOutput provides a single page of Extension results.
15const ListOutput = `
16{
17 "extensions": [
18 {
19 "updated": "2013-01-20T00:00:00-00:00",
20 "name": "Neutron Service Type Management",
21 "links": [],
22 "namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
23 "alias": "service-type",
24 "description": "API for retrieving service providers for Neutron advanced services"
25 }
26 ]
27}`
28
29// GetOutput provides a single Extension result.
30const GetOutput = `
31{
32 "extension": {
33 "updated": "2013-02-03T10:00:00-00:00",
34 "name": "agent",
35 "links": [],
36 "namespace": "http://docs.openstack.org/ext/agent/api/v2.0",
37 "alias": "agent",
38 "description": "The agent management extension."
39 }
40}
41`
42
43// ListedExtension is the Extension that should be parsed from ListOutput.
44var ListedExtension = Extension{
45 Updated: "2013-01-20T00:00:00-00:00",
46 Name: "Neutron Service Type Management",
47 Links: []interface{}{},
48 Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
49 Alias: "service-type",
50 Description: "API for retrieving service providers for Neutron advanced services",
51}
52
53// ExpectedExtensions is a slice containing the Extension that should be parsed from ListOutput.
54var ExpectedExtensions = []Extension{ListedExtension}
55
56// SingleExtension is the Extension that should be parsed from GetOutput.
57var SingleExtension = &Extension{
58 Updated: "2013-02-03T10:00:00-00:00",
59 Name: "agent",
60 Links: []interface{}{},
61 Namespace: "http://docs.openstack.org/ext/agent/api/v2.0",
62 Alias: "agent",
63 Description: "The agent management extension.",
64}
65
66// HandleListExtensionsSuccessfully creates an HTTP handler at `/extensions` on the test handler
67// mux that response with a list containing a single tenant.
68func HandleListExtensionsSuccessfully(t *testing.T) {
69 th.Mux.HandleFunc("/extensions", func(w http.ResponseWriter, r *http.Request) {
70 th.TestMethod(t, r, "GET")
71 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
72
73 w.Header().Add("Content-Type", "application/json")
74
75 fmt.Fprintf(w, ListOutput)
76 })
77}
78
79// HandleGetExtensionSuccessfully creates an HTTP handler at `/extensions/agent` that responds with
80// a JSON payload corresponding to SingleExtension.
81func HandleGetExtensionSuccessfully(t *testing.T) {
82 th.Mux.HandleFunc("/extensions/agent", func(w http.ResponseWriter, r *http.Request) {
83 th.TestMethod(t, r, "GET")
84 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
85
86 w.Header().Add("Content-Type", "application/json")
87 w.WriteHeader(http.StatusOK)
88
89 fmt.Fprintf(w, GetOutput)
90 })
91}