blob: 1cece865e63dd029e6e4b41fe5dff3e514f76412 [file] [log] [blame]
Ash Wilsonad21c712014-09-25 10:15:22 -04001package servers
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/pagination"
10 "github.com/rackspace/gophercloud/testhelper"
11)
12
13const tokenID = "bzbzbzbzbz"
14
15func serviceClient() *gophercloud.ServiceClient {
16 return &gophercloud.ServiceClient{
17 Provider: &gophercloud.ProviderClient{TokenID: tokenID},
18 Endpoint: testhelper.Endpoint(),
19 }
20}
21
22func TestListServers(t *testing.T) {
23 testhelper.SetupHTTP()
24 defer testhelper.TeardownHTTP()
25
26 testhelper.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
27 testhelper.TestMethod(t, r, "GET")
28 testhelper.TestHeader(t, r, "X-Auth-Token", tokenID)
29
30 w.Header().Add("Content-Type", "application/json")
31 r.ParseForm()
32 marker := r.Form.Get("marker")
33 switch marker {
34 case "":
35 fmt.Fprintf(w, serverListBody)
36 case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
37 fmt.Fprintf(w, `{ "servers": [] }`)
38 default:
39 t.Fatalf("/servers/detail invoked with unexpected marker=[%s]", marker)
40 }
41 })
42
43 client := serviceClient()
44 pages := 0
45 err := List(client).EachPage(func(page pagination.Page) (bool, error) {
46 pages++
47
48 actual, err := ExtractServers(page)
49 if err != nil {
50 return false, err
51 }
52
53 if len(actual) != 2 {
54 t.Fatalf("Expected 2 servers, got %d", len(actual))
55 }
56 equalServers(t, serverHerp, actual[0])
57 equalServers(t, serverDerp, actual[1])
58
59 return true, nil
60 })
61
62 if err != nil {
63 t.Fatalf("Unexpected error from EachPage: %v", err)
64 }
65 if pages != 1 {
66 t.Errorf("Expected 1 page, saw %d", pages)
67 }
68}
69
70func TestCreateServer(t *testing.T) {
71 testhelper.SetupHTTP()
72 defer testhelper.TeardownHTTP()
Ash Wilson3204d0d2014-09-25 10:37:44 -040073
74 testhelper.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
75 testhelper.TestMethod(t, r, "POST")
76 testhelper.TestHeader(t, r, "X-Auth-Token", tokenID)
77 testhelper.TestJSONRequest(t, r, `{
78 "server": {
79 "name": "derp",
80 "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb",
81 "flavorRef": "1"
82 }
83 }`)
84
85 w.WriteHeader(http.StatusAccepted)
86 w.Header().Add("Content-Type", "application/json")
87 fmt.Fprintf(w, singleServerBody)
88 })
89
90 client := serviceClient()
91 result, err := Create(client, map[string]interface{}{
92 "name": "derp",
93 "imageRef": "f90f6034-2570-4974-8351-6b49732ef2eb",
94 "flavorRef": "1",
95 })
96 if err != nil {
97 t.Fatalf("Unexpected Create error: %v", err)
98 }
99
100 actual, err := ExtractServer(result)
101 if err != nil {
102 t.Fatalf("Unexpected ExtractServer error: %v", err)
103 }
104
105 equalServers(t, serverDerp, *actual)
Ash Wilsonad21c712014-09-25 10:15:22 -0400106}
107
108func TestDeleteServer(t *testing.T) {
109 testhelper.SetupHTTP()
110 defer testhelper.TeardownHTTP()
111 t.Error("Pending")
112}
113
114func TestGetServer(t *testing.T) {
115 testhelper.SetupHTTP()
116 defer testhelper.TeardownHTTP()
117 t.Error("Pending")
118}
119
120func TestUpdateServer(t *testing.T) {
121 testhelper.SetupHTTP()
122 defer testhelper.TeardownHTTP()
123 t.Error("Pending")
124}
125
126func TestChangeServerAdminPassword(t *testing.T) {
127 testhelper.SetupHTTP()
128 defer testhelper.TeardownHTTP()
129 t.Error("Pending")
130}
131
132func TestRebootServer(t *testing.T) {
133 testhelper.SetupHTTP()
134 defer testhelper.TeardownHTTP()
135 t.Error("Pending")
136}
137
138func TestRebuildServer(t *testing.T) {
139 testhelper.SetupHTTP()
140 defer testhelper.TeardownHTTP()
141 t.Error("Pending")
142}
143
144func TestResizeServer(t *testing.T) {
145 testhelper.SetupHTTP()
146 defer testhelper.TeardownHTTP()
147 t.Error("Pending")
148}
149
150func TestConfirmResize(t *testing.T) {
151 testhelper.SetupHTTP()
152 defer testhelper.TeardownHTTP()
153 t.Error("Pending")
154}
155
156func TestRevertResize(t *testing.T) {
157 testhelper.SetupHTTP()
158 defer testhelper.TeardownHTTP()
159 t.Error("Pending")
160}