blob: ae5a91b8f928176a5d83e596f3d993785d969a1e [file] [log] [blame]
Ash Wilsonf4d63632014-10-09 14:54:06 -04001package extensions
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 common "github.com/rackspace/gophercloud/openstack/common/extensions"
9 os "github.com/rackspace/gophercloud/openstack/identity/v2/extensions"
10 "github.com/rackspace/gophercloud/pagination"
11 th "github.com/rackspace/gophercloud/testhelper"
12 fake "github.com/rackspace/gophercloud/testhelper/client"
13)
14
15func TestList(t *testing.T) {
16 th.SetupHTTP()
17 defer th.TeardownHTTP()
18
19 th.Mux.HandleFunc("/extensions", func(w http.ResponseWriter, r *http.Request) {
20 th.TestMethod(t, r, "GET")
21 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
22
23 w.Header().Add("Content-Type", "application/json")
24
25 fmt.Fprintf(w, `
26{
27 "extensions": [
28 {
29 "updated": "2013-01-20T00:00:00-00:00",
30 "name": "Neutron Service Type Management",
31 "links": [],
32 "namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
33 "alias": "service-type",
34 "description": "API for retrieving service providers for Neutron advanced services"
35 }
36 ]
37}
38 `)
39 })
40
41 count := 0
42
43 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
44 count++
45 actual, err := ExtractExtensions(page)
46 th.AssertNoErr(t, err)
47
48 expected := []os.Extension{
49 os.Extension{
50 Extension: common.Extension{
51 Updated: "2013-01-20T00:00:00-00:00",
52 Name: "Neutron Service Type Management",
53 Links: []interface{}{},
54 Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
55 Alias: "service-type",
56 Description: "API for retrieving service providers for Neutron advanced services",
57 },
58 },
59 }
60
61 th.AssertDeepEquals(t, expected, actual)
62
63 return true, nil
64 })
65 th.AssertNoErr(t, err)
66 th.CheckEquals(t, 1, count)
67}
68
69func TestGet(t *testing.T) {
70 th.SetupHTTP()
71 defer th.TeardownHTTP()
72
73 th.Mux.HandleFunc("/extensions/agent", func(w http.ResponseWriter, r *http.Request) {
74 th.TestMethod(t, r, "GET")
75 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
76
77 w.Header().Add("Content-Type", "application/json")
78 w.WriteHeader(http.StatusOK)
79
80 fmt.Fprintf(w, `
81{
82 "extension": {
83 "updated": "2013-02-03T10:00:00-00:00",
84 "name": "agent",
85 "links": [],
86 "namespace": "http://docs.openstack.org/ext/agent/api/v2.0",
87 "alias": "agent",
88 "description": "The agent management extension."
89 }
90}
91 `)
92
93 ext, err := Get(fake.ServiceClient(), "agent").Extract()
94 th.AssertNoErr(t, err)
95
96 th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00")
97 th.AssertEquals(t, ext.Name, "agent")
98 th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0")
99 th.AssertEquals(t, ext.Alias, "agent")
100 th.AssertEquals(t, ext.Description, "The agent management extension.")
101 })
102}