blob: 3a14c9936b417dd30f486b0d9c80c92b1461bd5d [file] [log] [blame]
Jon Perrittfd53bba2014-10-03 00:41:22 -05001package apiversions
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud/pagination"
9 th "github.com/gophercloud/gophercloud/testhelper"
10 "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perrittfd53bba2014-10-03 00:41:22 -050011)
12
Jon Perrittfd53bba2014-10-03 00:41:22 -050013func TestListVersions(t *testing.T) {
14 th.SetupHTTP()
15 defer th.TeardownHTTP()
16
17 th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 th.TestMethod(t, r, "GET")
Ash Wilsonff899c12014-10-22 09:14:30 -040019 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
Jon Perrittfd53bba2014-10-03 00:41:22 -050020
21 w.Header().Add("Content-Type", "application/json")
22 w.WriteHeader(http.StatusOK)
23
24 fmt.Fprintf(w, `{
25 "versions": [
26 {
27 "status": "CURRENT",
28 "updated": "2012-01-04T11:33:21Z",
29 "id": "v1.0",
30 "links": [
31 {
32 "href": "http://23.253.228.211:8776/v1/",
33 "rel": "self"
34 }
35 ]
36 },
37 {
38 "status": "CURRENT",
39 "updated": "2012-11-21T11:33:21Z",
40 "id": "v2.0",
41 "links": [
42 {
43 "href": "http://23.253.228.211:8776/v2/",
44 "rel": "self"
45 }
46 ]
47 }
48 ]
49 }`)
50 })
51
52 count := 0
53
Ash Wilsonff899c12014-10-22 09:14:30 -040054 List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
Jon Perrittfd53bba2014-10-03 00:41:22 -050055 count++
56 actual, err := ExtractAPIVersions(page)
Jon Perritt12395212016-02-24 10:41:17 -060057 th.AssertNoErr(t, err)
Jon Perrittfd53bba2014-10-03 00:41:22 -050058
59 expected := []APIVersion{
60 APIVersion{
61 ID: "v1.0",
62 Status: "CURRENT",
63 Updated: "2012-01-04T11:33:21Z",
64 },
65 APIVersion{
66 ID: "v2.0",
67 Status: "CURRENT",
68 Updated: "2012-11-21T11:33:21Z",
69 },
70 }
71
72 th.AssertDeepEquals(t, expected, actual)
73
74 return true, nil
75 })
76
Jon Perritt12395212016-02-24 10:41:17 -060077 th.AssertEquals(t, 1, count)
Jon Perrittfd53bba2014-10-03 00:41:22 -050078}
79
80func TestAPIInfo(t *testing.T) {
81 th.SetupHTTP()
82 defer th.TeardownHTTP()
83
84 th.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
85 th.TestMethod(t, r, "GET")
Ash Wilsonff899c12014-10-22 09:14:30 -040086 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
Jon Perrittfd53bba2014-10-03 00:41:22 -050087
88 w.Header().Add("Content-Type", "application/json")
89 w.WriteHeader(http.StatusOK)
90
91 fmt.Fprintf(w, `{
92 "version": {
93 "status": "CURRENT",
94 "updated": "2012-01-04T11:33:21Z",
95 "media-types": [
96 {
97 "base": "application/xml",
98 "type": "application/vnd.openstack.volume+xml;version=1"
99 },
100 {
101 "base": "application/json",
102 "type": "application/vnd.openstack.volume+json;version=1"
103 }
104 ],
105 "id": "v1.0",
106 "links": [
107 {
108 "href": "http://23.253.228.211:8776/v1/",
109 "rel": "self"
110 },
111 {
112 "href": "http://jorgew.github.com/block-storage-api/content/os-block-storage-1.0.pdf",
113 "type": "application/pdf",
114 "rel": "describedby"
115 },
116 {
117 "href": "http://docs.rackspacecloud.com/servers/api/v1.1/application.wadl",
118 "type": "application/vnd.sun.wadl+xml",
119 "rel": "describedby"
120 }
121 ]
122 }
123 }`)
124 })
125
Ash Wilsonff899c12014-10-22 09:14:30 -0400126 actual, err := Get(client.ServiceClient(), "v1").Extract()
Jon Perritt12395212016-02-24 10:41:17 -0600127 th.AssertNoErr(t, err)
Jon Perrittfd53bba2014-10-03 00:41:22 -0500128
129 expected := APIVersion{
130 ID: "v1.0",
131 Status: "CURRENT",
132 Updated: "2012-01-04T11:33:21Z",
133 }
134
135 th.AssertEquals(t, actual.ID, expected.ID)
136 th.AssertEquals(t, actual.Status, expected.Status)
137 th.AssertEquals(t, actual.Updated, expected.Updated)
138}