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