jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | "time" |
| 8 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame^] | 9 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 10 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/orchestration/v1/stackevents" |
| 11 | th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper" |
| 12 | fake "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client" |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 13 | ) |
| 14 | |
| 15 | // FindExpected represents the expected object from a Find request. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 16 | var FindExpected = []stackevents.Event{ |
| 17 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 18 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 19 | Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 20 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 21 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 22 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 23 | Rel: "self", |
| 24 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 25 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 26 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 27 | Rel: "resource", |
| 28 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 29 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 30 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 31 | Rel: "stack", |
| 32 | }, |
| 33 | }, |
| 34 | LogicalResourceID: "hello_world", |
| 35 | ResourceStatusReason: "state changed", |
| 36 | ResourceStatus: "CREATE_IN_PROGRESS", |
| 37 | PhysicalResourceID: "", |
| 38 | ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 39 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 40 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 41 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 42 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 43 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 44 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 45 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 46 | Rel: "self", |
| 47 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 48 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 49 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 50 | Rel: "resource", |
| 51 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 52 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 53 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 54 | Rel: "stack", |
| 55 | }, |
| 56 | }, |
| 57 | LogicalResourceID: "hello_world", |
| 58 | ResourceStatusReason: "state changed", |
| 59 | ResourceStatus: "CREATE_COMPLETE", |
| 60 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 61 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | // FindOutput represents the response body from a Find request. |
| 66 | const FindOutput = ` |
| 67 | { |
| 68 | "events": [ |
| 69 | { |
| 70 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 71 | "event_time": "2015-02-05T21:33:11", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 72 | "links": [ |
| 73 | { |
| 74 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 75 | "rel": "self" |
| 76 | }, |
| 77 | { |
| 78 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 79 | "rel": "resource" |
| 80 | }, |
| 81 | { |
| 82 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 83 | "rel": "stack" |
| 84 | } |
| 85 | ], |
| 86 | "logical_resource_id": "hello_world", |
| 87 | "resource_status_reason": "state changed", |
| 88 | "resource_status": "CREATE_IN_PROGRESS", |
| 89 | "physical_resource_id": null, |
| 90 | "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" |
| 91 | }, |
| 92 | { |
| 93 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 94 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 95 | "links": [ |
| 96 | { |
| 97 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 98 | "rel": "self" |
| 99 | }, |
| 100 | { |
| 101 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 102 | "rel": "resource" |
| 103 | }, |
| 104 | { |
| 105 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 106 | "rel": "stack" |
| 107 | } |
| 108 | ], |
| 109 | "logical_resource_id": "hello_world", |
| 110 | "resource_status_reason": "state changed", |
| 111 | "resource_status": "CREATE_COMPLETE", |
| 112 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 113 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 114 | } |
| 115 | ] |
| 116 | }` |
| 117 | |
| 118 | // HandleFindSuccessfully creates an HTTP handler at `/stacks/postman_stack/events` |
| 119 | // on the test handler mux that responds with a `Find` response. |
| 120 | func HandleFindSuccessfully(t *testing.T, output string) { |
| 121 | th.Mux.HandleFunc("/stacks/postman_stack/events", func(w http.ResponseWriter, r *http.Request) { |
| 122 | th.TestMethod(t, r, "GET") |
| 123 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 124 | th.TestHeader(t, r, "Accept", "application/json") |
| 125 | |
| 126 | w.Header().Set("Content-Type", "application/json") |
| 127 | w.WriteHeader(http.StatusOK) |
| 128 | fmt.Fprintf(w, output) |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | // ListExpected represents the expected object from a List request. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 133 | var ListExpected = []stackevents.Event{ |
| 134 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 135 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 136 | Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 137 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 138 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 139 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 140 | Rel: "self", |
| 141 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 142 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 143 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 144 | Rel: "resource", |
| 145 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 146 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 147 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 148 | Rel: "stack", |
| 149 | }, |
| 150 | }, |
| 151 | LogicalResourceID: "hello_world", |
| 152 | ResourceStatusReason: "state changed", |
| 153 | ResourceStatus: "CREATE_IN_PROGRESS", |
| 154 | PhysicalResourceID: "", |
| 155 | ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 156 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 157 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 158 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 159 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 160 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 161 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 162 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 163 | Rel: "self", |
| 164 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 165 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 166 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 167 | Rel: "resource", |
| 168 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 169 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 170 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 171 | Rel: "stack", |
| 172 | }, |
| 173 | }, |
| 174 | LogicalResourceID: "hello_world", |
| 175 | ResourceStatusReason: "state changed", |
| 176 | ResourceStatus: "CREATE_COMPLETE", |
| 177 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 178 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 179 | }, |
| 180 | } |
| 181 | |
| 182 | // ListOutput represents the response body from a List request. |
| 183 | const ListOutput = ` |
| 184 | { |
| 185 | "events": [ |
| 186 | { |
| 187 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 188 | "event_time": "2015-02-05T21:33:11", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 189 | "links": [ |
| 190 | { |
| 191 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 192 | "rel": "self" |
| 193 | }, |
| 194 | { |
| 195 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 196 | "rel": "resource" |
| 197 | }, |
| 198 | { |
| 199 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 200 | "rel": "stack" |
| 201 | } |
| 202 | ], |
| 203 | "logical_resource_id": "hello_world", |
| 204 | "resource_status_reason": "state changed", |
| 205 | "resource_status": "CREATE_IN_PROGRESS", |
| 206 | "physical_resource_id": null, |
| 207 | "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" |
| 208 | }, |
| 209 | { |
| 210 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 211 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 212 | "links": [ |
| 213 | { |
| 214 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 215 | "rel": "self" |
| 216 | }, |
| 217 | { |
| 218 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 219 | "rel": "resource" |
| 220 | }, |
| 221 | { |
| 222 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 223 | "rel": "stack" |
| 224 | } |
| 225 | ], |
| 226 | "logical_resource_id": "hello_world", |
| 227 | "resource_status_reason": "state changed", |
| 228 | "resource_status": "CREATE_COMPLETE", |
| 229 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 230 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 231 | } |
| 232 | ] |
| 233 | }` |
| 234 | |
| 235 | // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events` |
| 236 | // on the test handler mux that responds with a `List` response. |
| 237 | func HandleListSuccessfully(t *testing.T, output string) { |
| 238 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events", func(w http.ResponseWriter, r *http.Request) { |
| 239 | th.TestMethod(t, r, "GET") |
| 240 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 241 | th.TestHeader(t, r, "Accept", "application/json") |
| 242 | |
| 243 | w.Header().Set("Content-Type", "application/json") |
| 244 | r.ParseForm() |
| 245 | marker := r.Form.Get("marker") |
| 246 | switch marker { |
| 247 | case "": |
| 248 | fmt.Fprintf(w, output) |
| 249 | case "93940999-7d40-44ae-8de4-19624e7b8d18": |
| 250 | fmt.Fprintf(w, `{"events":[]}`) |
| 251 | default: |
| 252 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 253 | } |
| 254 | }) |
| 255 | } |
| 256 | |
| 257 | // ListResourceEventsExpected represents the expected object from a ListResourceEvents request. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 258 | var ListResourceEventsExpected = []stackevents.Event{ |
| 259 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 260 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 261 | Time: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 262 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 263 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 264 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 265 | Rel: "self", |
| 266 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 267 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 268 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 269 | Rel: "resource", |
| 270 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 271 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 272 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 273 | Rel: "stack", |
| 274 | }, |
| 275 | }, |
| 276 | LogicalResourceID: "hello_world", |
| 277 | ResourceStatusReason: "state changed", |
| 278 | ResourceStatus: "CREATE_IN_PROGRESS", |
| 279 | PhysicalResourceID: "", |
| 280 | ID: "06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 281 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 282 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 283 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 284 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 285 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 286 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 287 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 288 | Rel: "self", |
| 289 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 290 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 291 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 292 | Rel: "resource", |
| 293 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 294 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 295 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 296 | Rel: "stack", |
| 297 | }, |
| 298 | }, |
| 299 | LogicalResourceID: "hello_world", |
| 300 | ResourceStatusReason: "state changed", |
| 301 | ResourceStatus: "CREATE_COMPLETE", |
| 302 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 303 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 304 | }, |
| 305 | } |
| 306 | |
| 307 | // ListResourceEventsOutput represents the response body from a ListResourceEvents request. |
| 308 | const ListResourceEventsOutput = ` |
| 309 | { |
| 310 | "events": [ |
| 311 | { |
| 312 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 313 | "event_time": "2015-02-05T21:33:11", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 314 | "links": [ |
| 315 | { |
| 316 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a", |
| 317 | "rel": "self" |
| 318 | }, |
| 319 | { |
| 320 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 321 | "rel": "resource" |
| 322 | }, |
| 323 | { |
| 324 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 325 | "rel": "stack" |
| 326 | } |
| 327 | ], |
| 328 | "logical_resource_id": "hello_world", |
| 329 | "resource_status_reason": "state changed", |
| 330 | "resource_status": "CREATE_IN_PROGRESS", |
| 331 | "physical_resource_id": null, |
| 332 | "id": "06feb26f-9298-4a9b-8749-9d770e5d577a" |
| 333 | }, |
| 334 | { |
| 335 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 336 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 337 | "links": [ |
| 338 | { |
| 339 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 340 | "rel": "self" |
| 341 | }, |
| 342 | { |
| 343 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 344 | "rel": "resource" |
| 345 | }, |
| 346 | { |
| 347 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 348 | "rel": "stack" |
| 349 | } |
| 350 | ], |
| 351 | "logical_resource_id": "hello_world", |
| 352 | "resource_status_reason": "state changed", |
| 353 | "resource_status": "CREATE_COMPLETE", |
| 354 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 355 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 356 | } |
| 357 | ] |
| 358 | }` |
| 359 | |
| 360 | // HandleListResourceEventsSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events` |
| 361 | // on the test handler mux that responds with a `ListResourceEvents` response. |
| 362 | func HandleListResourceEventsSuccessfully(t *testing.T, output string) { |
| 363 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events", func(w http.ResponseWriter, r *http.Request) { |
| 364 | th.TestMethod(t, r, "GET") |
| 365 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 366 | th.TestHeader(t, r, "Accept", "application/json") |
| 367 | |
| 368 | w.Header().Set("Content-Type", "application/json") |
| 369 | r.ParseForm() |
| 370 | marker := r.Form.Get("marker") |
| 371 | switch marker { |
| 372 | case "": |
| 373 | fmt.Fprintf(w, output) |
| 374 | case "93940999-7d40-44ae-8de4-19624e7b8d18": |
| 375 | fmt.Fprintf(w, `{"events":[]}`) |
| 376 | default: |
| 377 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 378 | } |
| 379 | }) |
| 380 | } |
| 381 | |
| 382 | // GetExpected represents the expected object from a Get request. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 383 | var GetExpected = &stackevents.Event{ |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 384 | ResourceName: "hello_world", |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 385 | Time: time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC), |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 386 | Links: []gophercloud.Link{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 387 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 388 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 389 | Rel: "self", |
| 390 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 391 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 392 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 393 | Rel: "resource", |
| 394 | }, |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 395 | { |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 396 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 397 | Rel: "stack", |
| 398 | }, |
| 399 | }, |
| 400 | LogicalResourceID: "hello_world", |
| 401 | ResourceStatusReason: "state changed", |
| 402 | ResourceStatus: "CREATE_COMPLETE", |
| 403 | PhysicalResourceID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 404 | ID: "93940999-7d40-44ae-8de4-19624e7b8d18", |
| 405 | } |
| 406 | |
| 407 | // GetOutput represents the response body from a Get request. |
| 408 | const GetOutput = ` |
| 409 | { |
| 410 | "event":{ |
| 411 | "resource_name": "hello_world", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 412 | "event_time": "2015-02-05T21:33:27", |
Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 413 | "links": [ |
| 414 | { |
| 415 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18", |
| 416 | "rel": "self" |
| 417 | }, |
| 418 | { |
| 419 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 420 | "rel": "resource" |
| 421 | }, |
| 422 | { |
| 423 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 424 | "rel": "stack" |
| 425 | } |
| 426 | ], |
| 427 | "logical_resource_id": "hello_world", |
| 428 | "resource_status_reason": "state changed", |
| 429 | "resource_status": "CREATE_COMPLETE", |
| 430 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 431 | "id": "93940999-7d40-44ae-8de4-19624e7b8d18" |
| 432 | } |
| 433 | }` |
| 434 | |
| 435 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events/93940999-7d40-44ae-8de4-19624e7b8d18` |
| 436 | // on the test handler mux that responds with a `Get` response. |
| 437 | func HandleGetSuccessfully(t *testing.T, output string) { |
| 438 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources/my_resource/events/93940999-7d40-44ae-8de4-19624e7b8d18", func(w http.ResponseWriter, r *http.Request) { |
| 439 | th.TestMethod(t, r, "GET") |
| 440 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 441 | th.TestHeader(t, r, "Accept", "application/json") |
| 442 | |
| 443 | w.Header().Set("Content-Type", "application/json") |
| 444 | w.WriteHeader(http.StatusOK) |
| 445 | fmt.Fprintf(w, output) |
| 446 | }) |
| 447 | } |