blob: b4a094c0cf86d40f3573c1ce819986feef4b2cae [file] [log] [blame]
Samuel A. Falvo IIc007c272014-02-10 20:49:26 -08001package servers
2
3import (
Samuel A. Falvo IIc007c272014-02-10 20:49:26 -08004 "encoding/json"
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -08005 "testing"
Samuel A. Falvo IIc007c272014-02-10 20:49:26 -08006)
7
8// Taken from: http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html
9const goodListServersResult = `{
10"servers": [
11{
12"id": "52415800-8b69-11e0-9b19-734f6af67565",
13"tenant_id": "1234",
14"user_id": "5678",
15"name": "sample-server",
16"updated": "2010-10-10T12:00:00Z",
17"created": "2010-08-10T12:00:00Z",
18"hostId": "e4d909c290d0fb1ca068ffaddf22cbd0",
19"status": "BUILD",
20"progress": 60,
21"accessIPv4" : "67.23.10.132",
22"accessIPv6" : "::babe:67.23.10.132",
23"image" : {
24"id": "52415800-8b69-11e0-9b19-734f6f006e54",
25"links": [
26{
27"rel": "self",
28"href": "http://servers.api.openstack.org/v2/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"
29},
30{
31"rel": "bookmark",
32"href": "http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"
33}
34]
35},
36"flavor" : {
37"id": "52415800-8b69-11e0-9b19-734f216543fd",
38"links": [
39{
40"rel": "self",
41"href": "http://servers.api.openstack.org/v2/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"
42},
43{
44"rel": "bookmark",
45"href": "http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"
46}
47]
48},
49"addresses": {
50"public" : [
51{
52"version": 4,
53"addr": "67.23.10.132"
54},
55{
56"version": 6,
57"addr": "::babe:67.23.10.132"
58},
59{
60"version": 4,
61"addr": "67.23.10.131"
62},
63{
64"version": 6,
65"addr": "::babe:4317:0A83"
66}
67],
68"private" : [
69{
70"version": 4,
71"addr": "10.176.42.16"
72},
73{
74"version": 6,
75"addr": "::babe:10.176.42.16"
76}
77]
78},
79"metadata": {
80"Server Label": "Web Head 1",
81"Image Version": "2.1"
82},
83"links": [
84{
85"rel": "self",
86"href": "http://servers.api.openstack.org/v2/1234/servers/52415800-8b69-11e0-9b19-734f6af67565"
87},
88{
89"rel": "bookmark",
90"href": "http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f6af67565"
91}
92]
93},
94{
95"id": "52415800-8b69-11e0-9b19-734f1f1350e5",
96"user_id": "5678",
97"name": "sample-server2",
98"tenant_id": "1234",
99"updated": "2010-10-10T12:00:00Z",
100"created": "2010-08-10T12:00:00Z",
101"hostId": "9e107d9d372bb6826bd81d3542a419d6",
102"status": "ACTIVE",
103"accessIPv4" : "67.23.10.133",
104"accessIPv6" : "::babe:67.23.10.133",
105"image" : {
106"id": "52415800-8b69-11e0-9b19-734f5736d2a2",
107"links": [
108{
109"rel": "self",
110"href": "http://servers.api.openstack.org/v2/1234/images/52415800-8b69-11e0-9b19-734f5736d2a2"
111},
112{
113"rel": "bookmark",
114"href": "http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f5736d2a2"
115}
116]
117},
118"flavor" : {
119"id": "52415800-8b69-11e0-9b19-734f216543fd",
120"links": [
121{
122"rel": "self",
123"href": "http://servers.api.openstack.org/v2/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"
124},
125{
126"rel": "bookmark",
127"href": "http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"
128}
129]
130},
131"addresses": {
132"public" : [
133{
134"version": 4,
135"addr": "67.23.10.133"
136},
137{
138"version": 6,
139"addr": "::babe:67.23.10.133"
140}
141],
142"private" : [
143{
144"version": 4,
145"addr": "10.176.42.17"
146},
147{
148"version": 6,
149"addr": "::babe:10.176.42.17"
150}
151]
152},
153"metadata": {
154"Server Label": "DB 1"
155},
156"links": [
157{
158"rel": "self",
159"href": "http://servers.api.openstack.org/v2/1234/servers/52415800-8b69-11e0-9b19-734f1f1350e5"
160},
161{
162"rel": "bookmark",
163"href": "http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f1f1350e5"
164}
165]
166}
167]
168}`
169
170func TestGetServer(t *testing.T) {
171 var listResults map[string]interface{}
172 err := json.Unmarshal([]byte(goodListServersResult), &listResults)
173 if err != nil {
174 t.Error(err)
175 return
176 }
177
178 svrs, err := GetServers(listResults)
179 if err != nil {
180 t.Error(err)
181 return
182 }
183
184 if len(svrs) != 2 {
185 t.Errorf("Expected 2 servers; got %d", len(svrs))
186 return
187 }
188}