Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 1 | package stacks |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 7 | "time" |
Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 8 | |
| 9 | "github.com/rackspace/gophercloud" |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 12 | ) |
| 13 | |
| 14 | // CreateExpected represents the expected object from a Create request. |
| 15 | var CreateExpected = &CreatedStack{ |
| 16 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 17 | Links: []gophercloud.Link{ |
| 18 | gophercloud.Link{ |
| 19 | Href: "http://168.28.170.117:8004/v1/98606384f58drad0bhdb7d02779549ac/stacks/stackcreated/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 20 | Rel: "self", |
| 21 | }, |
| 22 | }, |
| 23 | } |
| 24 | |
| 25 | // CreateOutput represents the response body from a Create request. |
| 26 | const CreateOutput = ` |
| 27 | { |
| 28 | "stack": { |
| 29 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 30 | "links": [ |
| 31 | { |
| 32 | "href": "http://168.28.170.117:8004/v1/98606384f58drad0bhdb7d02779549ac/stacks/stackcreated/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 33 | "rel": "self" |
| 34 | } |
| 35 | ] |
| 36 | } |
| 37 | }` |
| 38 | |
| 39 | // HandleCreateSuccessfully creates an HTTP handler at `/stacks` on the test handler mux |
| 40 | // that responds with a `Create` response. |
| 41 | func HandleCreateSuccessfully(t *testing.T, output string) { |
| 42 | th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) { |
| 43 | th.TestMethod(t, r, "POST") |
| 44 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 45 | th.TestHeader(t, r, "Accept", "application/json") |
| 46 | w.WriteHeader(http.StatusCreated) |
| 47 | fmt.Fprintf(w, output) |
| 48 | }) |
| 49 | } |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 50 | |
| 51 | // ListExpected represents the expected object from a List request. |
| 52 | var ListExpected = []ListedStack{ |
| 53 | ListedStack{ |
| 54 | Description: "Simple template to test heat commands", |
| 55 | Links: []gophercloud.Link{ |
| 56 | gophercloud.Link{ |
| 57 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 58 | Rel: "self", |
| 59 | }, |
| 60 | }, |
| 61 | StatusReason: "Stack CREATE completed successfully", |
| 62 | Name: "postman_stack", |
| 63 | CreationTime: time.Date(2015, 2, 3, 20, 7, 39, 0, time.UTC), |
| 64 | Status: "CREATE_COMPLETE", |
| 65 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 66 | }, |
| 67 | ListedStack{ |
| 68 | Description: "Simple template to test heat commands", |
| 69 | Links: []gophercloud.Link{ |
| 70 | gophercloud.Link{ |
| 71 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", |
| 72 | Rel: "self", |
| 73 | }, |
| 74 | }, |
| 75 | StatusReason: "Stack successfully updated", |
| 76 | Name: "gophercloud-test-stack-2", |
| 77 | CreationTime: time.Date(2014, 12, 11, 17, 39, 16, 0, time.UTC), |
| 78 | UpdatedTime: time.Date(2014, 12, 11, 17, 40, 37, 0, time.UTC), |
| 79 | Status: "UPDATE_COMPLETE", |
| 80 | ID: "db6977b2-27aa-4775-9ae7-6213212d4ada", |
| 81 | }, |
| 82 | } |
| 83 | |
| 84 | // FullListOutput represents the response body from a List request without a marker. |
| 85 | const FullListOutput = ` |
| 86 | { |
| 87 | "stacks": [ |
| 88 | { |
| 89 | "description": "Simple template to test heat commands", |
| 90 | "links": [ |
| 91 | { |
| 92 | "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 93 | "rel": "self" |
| 94 | } |
| 95 | ], |
| 96 | "stack_status_reason": "Stack CREATE completed successfully", |
| 97 | "stack_name": "postman_stack", |
| 98 | "creation_time": "2015-02-03T20:07:39Z", |
| 99 | "updated_time": null, |
| 100 | "stack_status": "CREATE_COMPLETE", |
| 101 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87" |
| 102 | }, |
| 103 | { |
| 104 | "description": "Simple template to test heat commands", |
| 105 | "links": [ |
| 106 | { |
| 107 | "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", |
| 108 | "rel": "self" |
| 109 | } |
| 110 | ], |
| 111 | "stack_status_reason": "Stack successfully updated", |
| 112 | "stack_name": "gophercloud-test-stack-2", |
| 113 | "creation_time": "2014-12-11T17:39:16Z", |
| 114 | "updated_time": "2014-12-11T17:40:37Z", |
| 115 | "stack_status": "UPDATE_COMPLETE", |
| 116 | "id": "db6977b2-27aa-4775-9ae7-6213212d4ada" |
| 117 | } |
| 118 | ] |
| 119 | } |
| 120 | ` |
| 121 | |
| 122 | // HandleListSuccessfully creates an HTTP handler at `/stacks` on the test handler mux |
| 123 | // that responds with a `List` response. |
| 124 | func HandleListSuccessfully(t *testing.T, output string) { |
| 125 | th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) { |
| 126 | th.TestMethod(t, r, "GET") |
| 127 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 128 | th.TestHeader(t, r, "Accept", "application/json") |
| 129 | |
| 130 | w.Header().Set("Content-Type", "application/json") |
| 131 | r.ParseForm() |
| 132 | marker := r.Form.Get("marker") |
| 133 | switch marker { |
| 134 | case "": |
| 135 | fmt.Fprintf(w, output) |
| 136 | case "db6977b2-27aa-4775-9ae7-6213212d4ada": |
| 137 | fmt.Fprintf(w, `[]`) |
| 138 | default: |
| 139 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 140 | } |
| 141 | }) |
| 142 | } |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 143 | |
| 144 | // GetExpected represents the expected object from a Get request. |
| 145 | var GetExpected = &RetrievedStack{ |
| 146 | DisableRollback: true, |
| 147 | Description: "Simple template to test heat commands", |
| 148 | Parameters: map[string]string{ |
| 149 | "flavor": "m1.tiny", |
| 150 | "OS::stack_name": "postman_stack", |
| 151 | "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 152 | }, |
| 153 | StatusReason: "Stack CREATE completed successfully", |
| 154 | Name: "postman_stack", |
| 155 | Outputs: []map[string]interface{}{}, |
| 156 | CreationTime: time.Date(2015, 2, 3, 20, 7, 39, 0, time.UTC), |
| 157 | Links: []gophercloud.Link{ |
| 158 | gophercloud.Link{ |
| 159 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 160 | Rel: "self", |
| 161 | }, |
| 162 | }, |
| 163 | Capabilities: []interface{}{}, |
| 164 | NotificationTopics: []interface{}{}, |
| 165 | Status: "CREATE_COMPLETE", |
| 166 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 167 | TemplateDescription: "Simple template to test heat commands", |
| 168 | } |
| 169 | |
| 170 | // GetOutput represents the response body from a Get request. |
| 171 | const GetOutput = ` |
| 172 | { |
| 173 | "stack": { |
| 174 | "disable_rollback": true, |
| 175 | "description": "Simple template to test heat commands", |
| 176 | "parameters": { |
| 177 | "flavor": "m1.tiny", |
| 178 | "OS::stack_name": "postman_stack", |
| 179 | "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87" |
| 180 | }, |
| 181 | "stack_status_reason": "Stack CREATE completed successfully", |
| 182 | "stack_name": "postman_stack", |
| 183 | "outputs": [], |
| 184 | "creation_time": "2015-02-03T20:07:39Z", |
| 185 | "links": [ |
| 186 | { |
| 187 | "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 188 | "rel": "self" |
| 189 | } |
| 190 | ], |
| 191 | "capabilities": [], |
| 192 | "notification_topics": [], |
| 193 | "timeout_mins": null, |
| 194 | "stack_status": "CREATE_COMPLETE", |
| 195 | "updated_time": null, |
| 196 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 197 | "template_description": "Simple template to test heat commands" |
| 198 | } |
| 199 | } |
| 200 | ` |
| 201 | |
| 202 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` |
| 203 | // on the test handler mux that responds with a `Get` response. |
| 204 | func HandleGetSuccessfully(t *testing.T, output string) { |
| 205 | th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", func(w http.ResponseWriter, r *http.Request) { |
| 206 | th.TestMethod(t, r, "GET") |
| 207 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 208 | th.TestHeader(t, r, "Accept", "application/json") |
| 209 | |
| 210 | w.Header().Set("Content-Type", "application/json") |
| 211 | w.WriteHeader(http.StatusOK) |
| 212 | fmt.Fprintf(w, output) |
| 213 | }) |
| 214 | } |
| 215 | |
| 216 | // HandleUpdateSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` |
| 217 | // on the test handler mux that responds with an `Update` response. |
| 218 | func HandleUpdateSuccessfully(t *testing.T) { |
| 219 | th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) { |
| 220 | th.TestMethod(t, r, "PUT") |
| 221 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 222 | th.TestHeader(t, r, "Accept", "application/json") |
| 223 | |
| 224 | w.Header().Set("Content-Type", "application/json") |
| 225 | w.WriteHeader(http.StatusAccepted) |
| 226 | }) |
| 227 | } |
Jon Perritt | a433dd9 | 2015-02-04 18:04:13 -0700 | [diff] [blame] | 228 | |
| 229 | // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` |
| 230 | // on the test handler mux that responds with an `Delete` response. |
| 231 | func HandleDeleteSuccessfully(t *testing.T) { |
| 232 | th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) { |
| 233 | th.TestMethod(t, r, "DELETE") |
| 234 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 235 | th.TestHeader(t, r, "Accept", "application/json") |
| 236 | |
| 237 | w.Header().Set("Content-Type", "application/json") |
| 238 | w.WriteHeader(http.StatusNoContent) |
| 239 | }) |
| 240 | } |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame^] | 241 | |
| 242 | // GetExpected represents the expected object from a Get request. |
| 243 | var PreviewExpected = &PreviewedStack{ |
| 244 | DisableRollback: true, |
| 245 | Description: "Simple template to test heat commands", |
| 246 | Parameters: map[string]string{ |
| 247 | "flavor": "m1.tiny", |
| 248 | "OS::stack_name": "postman_stack", |
| 249 | "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 250 | }, |
| 251 | StatusReason: "Stack CREATE completed successfully", |
| 252 | Name: "postman_stack", |
| 253 | CreationTime: time.Date(2015, 2, 3, 20, 7, 39, 0, time.UTC), |
| 254 | Links: []gophercloud.Link{ |
| 255 | gophercloud.Link{ |
| 256 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 257 | Rel: "self", |
| 258 | }, |
| 259 | }, |
| 260 | Capabilities: []interface{}{}, |
| 261 | NotificationTopics: []interface{}{}, |
| 262 | Status: "CREATE_COMPLETE", |
| 263 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 264 | TemplateDescription: "Simple template to test heat commands", |
| 265 | } |
| 266 | |
| 267 | // HandlePreviewSuccessfully creates an HTTP handler at `/stacks/preview` |
| 268 | // on the test handler mux that responds with an `Preview` response. |
| 269 | func HandlePreviewSuccessfully(t *testing.T, output string) { |
| 270 | th.Mux.HandleFunc("/stacks/preview", func(w http.ResponseWriter, r *http.Request) { |
| 271 | th.TestMethod(t, r, "POST") |
| 272 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 273 | th.TestHeader(t, r, "Accept", "application/json") |
| 274 | |
| 275 | w.Header().Set("Content-Type", "application/json") |
| 276 | w.WriteHeader(http.StatusOK) |
| 277 | fmt.Fprintf(w, output) |
| 278 | }) |
| 279 | } |