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 | } |