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