Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 3 | package stackresources |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/rackspace/gophercloud" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 14 | ) |
| 15 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 16 | // FindExpected represents the expected object from a Find request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 17 | var FindExpected = []Resource{ |
| 18 | Resource{ |
| 19 | Name: "hello_world", |
| 20 | Links: []gophercloud.Link{ |
| 21 | gophercloud.Link{ |
| 22 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 23 | Rel: "self", |
| 24 | }, |
| 25 | gophercloud.Link{ |
| 26 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 27 | Rel: "stack", |
| 28 | }, |
| 29 | }, |
| 30 | LogicalID: "hello_world", |
| 31 | StatusReason: "state changed", |
| 32 | UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 33 | CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC), |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 34 | RequiredBy: []interface{}{}, |
| 35 | Status: "CREATE_IN_PROGRESS", |
| 36 | PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 37 | Type: "OS::Nova::Server", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 38 | Attributes: map[string]interface{}{"SXSW": "atx"}, |
| 39 | Description: "Some resource", |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 40 | }, |
| 41 | } |
| 42 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 43 | // FindOutput represents the response body from a Find request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 44 | const FindOutput = ` |
| 45 | { |
| 46 | "resources": [ |
| 47 | { |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 48 | "description": "Some resource", |
| 49 | "attributes": {"SXSW": "atx"}, |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 50 | "resource_name": "hello_world", |
| 51 | "links": [ |
| 52 | { |
| 53 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 54 | "rel": "self" |
| 55 | }, |
| 56 | { |
| 57 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 58 | "rel": "stack" |
| 59 | } |
| 60 | ], |
| 61 | "logical_resource_id": "hello_world", |
| 62 | "resource_status_reason": "state changed", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 63 | "updated_time": "2015-02-05T21:33:11", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 64 | "creation_time": "2015-02-05T21:33:10", |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 65 | "required_by": [], |
| 66 | "resource_status": "CREATE_IN_PROGRESS", |
| 67 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 68 | "resource_type": "OS::Nova::Server" |
| 69 | } |
| 70 | ] |
| 71 | }` |
| 72 | |
| 73 | // HandleFindSuccessfully creates an HTTP handler at `/stacks/hello_world/resources` |
| 74 | // on the test handler mux that responds with a `Find` response. |
| 75 | func HandleFindSuccessfully(t *testing.T, output string) { |
| 76 | th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) { |
| 77 | th.TestMethod(t, r, "GET") |
| 78 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 79 | th.TestHeader(t, r, "Accept", "application/json") |
| 80 | |
| 81 | w.Header().Set("Content-Type", "application/json") |
| 82 | w.WriteHeader(http.StatusOK) |
| 83 | fmt.Fprintf(w, output) |
| 84 | }) |
| 85 | } |
| 86 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 87 | // ListExpected represents the expected object from a List request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 88 | var ListExpected = []Resource{ |
| 89 | Resource{ |
| 90 | Name: "hello_world", |
| 91 | Links: []gophercloud.Link{ |
| 92 | gophercloud.Link{ |
| 93 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 94 | Rel: "self", |
| 95 | }, |
| 96 | gophercloud.Link{ |
| 97 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 98 | Rel: "stack", |
| 99 | }, |
| 100 | }, |
| 101 | LogicalID: "hello_world", |
| 102 | StatusReason: "state changed", |
| 103 | UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 104 | CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC), |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 105 | RequiredBy: []interface{}{}, |
| 106 | Status: "CREATE_IN_PROGRESS", |
| 107 | PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf", |
| 108 | Type: "OS::Nova::Server", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 109 | Attributes: map[string]interface{}{"SXSW": "atx"}, |
| 110 | Description: "Some resource", |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 111 | }, |
| 112 | } |
| 113 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 114 | // ListOutput represents the response body from a List request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 115 | const ListOutput = `{ |
| 116 | "resources": [ |
| 117 | { |
| 118 | "resource_name": "hello_world", |
| 119 | "links": [ |
| 120 | { |
| 121 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", |
| 122 | "rel": "self" |
| 123 | }, |
| 124 | { |
| 125 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", |
| 126 | "rel": "stack" |
| 127 | } |
| 128 | ], |
| 129 | "logical_resource_id": "hello_world", |
| 130 | "resource_status_reason": "state changed", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 131 | "updated_time": "2015-02-05T21:33:11", |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 132 | "required_by": [], |
| 133 | "resource_status": "CREATE_IN_PROGRESS", |
| 134 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 135 | "creation_time": "2015-02-05T21:33:10", |
| 136 | "resource_type": "OS::Nova::Server", |
| 137 | "attributes": {"SXSW": "atx"}, |
| 138 | "description": "Some resource" |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 139 | } |
| 140 | ] |
| 141 | }` |
| 142 | |
| 143 | // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources` |
| 144 | // on the test handler mux that responds with a `List` response. |
| 145 | func HandleListSuccessfully(t *testing.T, output string) { |
| 146 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources", func(w http.ResponseWriter, r *http.Request) { |
| 147 | th.TestMethod(t, r, "GET") |
| 148 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 149 | th.TestHeader(t, r, "Accept", "application/json") |
| 150 | |
| 151 | w.Header().Set("Content-Type", "application/json") |
| 152 | r.ParseForm() |
| 153 | marker := r.Form.Get("marker") |
| 154 | switch marker { |
| 155 | case "": |
| 156 | fmt.Fprintf(w, output) |
Jon Perritt | 64f594d | 2015-02-08 21:24:33 -0700 | [diff] [blame] | 157 | case "49181cd6-169a-4130-9455-31185bbfc5bf": |
| 158 | fmt.Fprintf(w, `{"resources":[]}`) |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 159 | default: |
| 160 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 161 | } |
| 162 | }) |
| 163 | } |
| 164 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 165 | // GetExpected represents the expected object from a Get request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 166 | var GetExpected = &Resource{ |
| 167 | Name: "wordpress_instance", |
| 168 | Links: []gophercloud.Link{ |
| 169 | gophercloud.Link{ |
| 170 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", |
| 171 | Rel: "self", |
| 172 | }, |
| 173 | gophercloud.Link{ |
| 174 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e", |
| 175 | Rel: "stack", |
| 176 | }, |
| 177 | }, |
| 178 | LogicalID: "wordpress_instance", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 179 | Attributes: map[string]interface{}{"SXSW": "atx"}, |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 180 | StatusReason: "state changed", |
| 181 | UpdatedTime: time.Date(2014, 12, 10, 18, 34, 35, 0, time.UTC), |
| 182 | RequiredBy: []interface{}{}, |
| 183 | Status: "CREATE_COMPLETE", |
| 184 | PhysicalID: "00e3a2fe-c65d-403c-9483-4db9930dd194", |
| 185 | Type: "OS::Nova::Server", |
| 186 | } |
| 187 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 188 | // GetOutput represents the response body from a Get request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 189 | const GetOutput = ` |
| 190 | { |
| 191 | "resource": { |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 192 | "description": "Some resource", |
| 193 | "attributes": {"SXSW": "atx"}, |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 194 | "resource_name": "wordpress_instance", |
| 195 | "description": "", |
| 196 | "links": [ |
| 197 | { |
| 198 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", |
| 199 | "rel": "self" |
| 200 | }, |
| 201 | { |
| 202 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e", |
| 203 | "rel": "stack" |
| 204 | } |
| 205 | ], |
| 206 | "logical_resource_id": "wordpress_instance", |
| 207 | "resource_status": "CREATE_COMPLETE", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 208 | "updated_time": "2014-12-10T18:34:35", |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 209 | "required_by": [], |
| 210 | "resource_status_reason": "state changed", |
| 211 | "physical_resource_id": "00e3a2fe-c65d-403c-9483-4db9930dd194", |
| 212 | "resource_type": "OS::Nova::Server" |
| 213 | } |
| 214 | }` |
| 215 | |
| 216 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance` |
| 217 | // on the test handler mux that responds with a `Get` response. |
| 218 | func HandleGetSuccessfully(t *testing.T, output string) { |
| 219 | th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", func(w http.ResponseWriter, r *http.Request) { |
| 220 | th.TestMethod(t, r, "GET") |
| 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.StatusOK) |
| 226 | fmt.Fprintf(w, output) |
| 227 | }) |
| 228 | } |
| 229 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 230 | // MetadataExpected represents the expected object from a Metadata request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 231 | var MetadataExpected = map[string]string{ |
| 232 | "number": "7", |
| 233 | "animal": "auk", |
| 234 | } |
| 235 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 236 | // MetadataOutput represents the response body from a Metadata request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 237 | const MetadataOutput = ` |
| 238 | { |
| 239 | "metadata": { |
| 240 | "number": "7", |
| 241 | "animal": "auk" |
| 242 | } |
| 243 | }` |
| 244 | |
| 245 | // HandleMetadataSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata` |
| 246 | // on the test handler mux that responds with a `Metadata` response. |
| 247 | func HandleMetadataSuccessfully(t *testing.T, output string) { |
| 248 | th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata", func(w http.ResponseWriter, r *http.Request) { |
| 249 | th.TestMethod(t, r, "GET") |
| 250 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 251 | th.TestHeader(t, r, "Accept", "application/json") |
| 252 | |
| 253 | w.Header().Set("Content-Type", "application/json") |
| 254 | w.WriteHeader(http.StatusOK) |
| 255 | fmt.Fprintf(w, output) |
| 256 | }) |
| 257 | } |
| 258 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 259 | // ListTypesExpected represents the expected object from a ListTypes request. |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 260 | var ListTypesExpected = ResourceTypes{ |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 261 | "OS::Nova::Server", |
| 262 | "OS::Heat::RandomString", |
| 263 | "OS::Swift::Container", |
| 264 | "OS::Trove::Instance", |
| 265 | "OS::Nova::FloatingIPAssociation", |
| 266 | "OS::Cinder::VolumeAttachment", |
| 267 | "OS::Nova::FloatingIP", |
| 268 | "OS::Nova::KeyPair", |
| 269 | } |
| 270 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 271 | // same as above, but sorted |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 272 | var SortedListTypesExpected = ResourceTypes{ |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 273 | "OS::Cinder::VolumeAttachment", |
| 274 | "OS::Heat::RandomString", |
| 275 | "OS::Nova::FloatingIP", |
| 276 | "OS::Nova::FloatingIPAssociation", |
| 277 | "OS::Nova::KeyPair", |
| 278 | "OS::Nova::Server", |
| 279 | "OS::Swift::Container", |
| 280 | "OS::Trove::Instance", |
| 281 | } |
| 282 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 283 | // ListTypesOutput represents the response body from a ListTypes request. |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 284 | const ListTypesOutput = ` |
| 285 | { |
| 286 | "resource_types": [ |
| 287 | "OS::Nova::Server", |
| 288 | "OS::Heat::RandomString", |
| 289 | "OS::Swift::Container", |
| 290 | "OS::Trove::Instance", |
| 291 | "OS::Nova::FloatingIPAssociation", |
| 292 | "OS::Cinder::VolumeAttachment", |
| 293 | "OS::Nova::FloatingIP", |
| 294 | "OS::Nova::KeyPair" |
| 295 | ] |
| 296 | }` |
| 297 | |
| 298 | // HandleListTypesSuccessfully creates an HTTP handler at `/resource_types` |
| 299 | // on the test handler mux that responds with a `ListTypes` response. |
| 300 | func HandleListTypesSuccessfully(t *testing.T, output string) { |
| 301 | th.Mux.HandleFunc("/resource_types", func(w http.ResponseWriter, r *http.Request) { |
| 302 | th.TestMethod(t, r, "GET") |
| 303 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 304 | th.TestHeader(t, r, "Accept", "application/json") |
| 305 | |
| 306 | w.Header().Set("Content-Type", "application/json") |
| 307 | w.WriteHeader(http.StatusOK) |
| 308 | fmt.Fprintf(w, output) |
| 309 | }) |
| 310 | } |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 311 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 312 | // GetSchemaExpected represents the expected object from a Schema request. |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 313 | var GetSchemaExpected = &TypeSchema{ |
| 314 | Attributes: map[string]interface{}{ |
| 315 | "an_attribute": map[string]interface{}{ |
| 316 | "description": "An attribute description .", |
| 317 | }, |
| 318 | }, |
| 319 | Properties: map[string]interface{}{ |
| 320 | "a_property": map[string]interface{}{ |
| 321 | "update_allowed": false, |
| 322 | "required": true, |
| 323 | "type": "string", |
| 324 | "description": "A resource description.", |
| 325 | }, |
| 326 | }, |
| 327 | ResourceType: "OS::Heat::AResourceName", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 328 | SupportStatus: map[string]interface{}{ |
| 329 | "message": "A status message", |
| 330 | "status": "SUPPORTED", |
| 331 | "version": "2014.1", |
| 332 | }, |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 335 | // GetSchemaOutput represents the response body from a Schema request. |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 336 | const GetSchemaOutput = ` |
| 337 | { |
| 338 | "attributes": { |
| 339 | "an_attribute": { |
| 340 | "description": "An attribute description ." |
| 341 | } |
| 342 | }, |
| 343 | "properties": { |
| 344 | "a_property": { |
| 345 | "update_allowed": false, |
| 346 | "required": true, |
| 347 | "type": "string", |
| 348 | "description": "A resource description." |
| 349 | } |
| 350 | }, |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 351 | "resource_type": "OS::Heat::AResourceName", |
| 352 | "support_status": { |
| 353 | "message": "A status message", |
| 354 | "status": "SUPPORTED", |
| 355 | "version": "2014.1" |
| 356 | } |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 357 | }` |
| 358 | |
| 359 | // HandleGetSchemaSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName` |
| 360 | // on the test handler mux that responds with a `Schema` response. |
| 361 | func HandleGetSchemaSuccessfully(t *testing.T, output string) { |
| 362 | th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName", func(w http.ResponseWriter, r *http.Request) { |
| 363 | th.TestMethod(t, r, "GET") |
| 364 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 365 | th.TestHeader(t, r, "Accept", "application/json") |
| 366 | |
| 367 | w.Header().Set("Content-Type", "application/json") |
| 368 | w.WriteHeader(http.StatusOK) |
| 369 | fmt.Fprintf(w, output) |
| 370 | }) |
| 371 | } |
| 372 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 373 | // GetTemplateExpected represents the expected object from a Template request. |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 374 | var GetTemplateExpected = "{\n \"HeatTemplateFormatVersion\": \"2012-12-12\",\n \"Outputs\": {\n \"private_key\": {\n \"Description\": \"The private key if it has been saved.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"private_key\\\"]}\"\n },\n \"public_key\": {\n \"Description\": \"The public key.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"public_key\\\"]}\"\n }\n },\n \"Parameters\": {\n \"name\": {\n \"Description\": \"The name of the key pair.\",\n \"Type\": \"String\"\n },\n \"public_key\": {\n \"Description\": \"The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.\",\n \"Type\": \"String\"\n },\n \"save_private_key\": {\n \"AllowedValues\": [\n \"True\",\n \"true\",\n \"False\",\n \"false\"\n ],\n \"Default\": false,\n \"Description\": \"True if the system should remember a generated private key; False otherwise.\",\n \"Type\": \"String\"\n }\n },\n \"Resources\": {\n \"KeyPair\": {\n \"Properties\": {\n \"name\": {\n \"Ref\": \"name\"\n },\n \"public_key\": {\n \"Ref\": \"public_key\"\n },\n \"save_private_key\": {\n \"Ref\": \"save_private_key\"\n }\n },\n \"Type\": \"OS::Nova::KeyPair\"\n }\n }\n}" |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 375 | |
Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 376 | // GetTemplateOutput represents the response body from a Template request. |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 377 | const GetTemplateOutput = ` |
| 378 | { |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 379 | "HeatTemplateFormatVersion": "2012-12-12", |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 380 | "Outputs": { |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 381 | "private_key": { |
| 382 | "Description": "The private key if it has been saved.", |
| 383 | "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 384 | }, |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 385 | "public_key": { |
| 386 | "Description": "The public key.", |
| 387 | "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 388 | } |
| 389 | }, |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 390 | "Parameters": { |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 391 | "name": { |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 392 | "Description": "The name of the key pair.", |
| 393 | "Type": "String" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 394 | }, |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 395 | "public_key": { |
| 396 | "Description": "The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.", |
| 397 | "Type": "String" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 398 | }, |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 399 | "save_private_key": { |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 400 | "AllowedValues": [ |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 401 | "True", |
| 402 | "true", |
| 403 | "False", |
| 404 | "false" |
| 405 | ], |
| 406 | "Default": false, |
| 407 | "Description": "True if the system should remember a generated private key; False otherwise.", |
| 408 | "Type": "String" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 409 | } |
| 410 | }, |
| 411 | "Resources": { |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 412 | "KeyPair": { |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 413 | "Properties": { |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 414 | "name": { |
| 415 | "Ref": "name" |
| 416 | }, |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 417 | "public_key": { |
| 418 | "Ref": "public_key" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 419 | }, |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 420 | "save_private_key": { |
| 421 | "Ref": "save_private_key" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 422 | } |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 423 | }, |
| 424 | "Type": "OS::Nova::KeyPair" |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | }` |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 428 | |
| 429 | // HandleGetTemplateSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName/template` |
| 430 | // on the test handler mux that responds with a `Template` response. |
| 431 | func HandleGetTemplateSuccessfully(t *testing.T, output string) { |
| 432 | th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName/template", func(w http.ResponseWriter, r *http.Request) { |
| 433 | th.TestMethod(t, r, "GET") |
| 434 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 435 | th.TestHeader(t, r, "Accept", "application/json") |
| 436 | |
| 437 | w.Header().Set("Content-Type", "application/json") |
| 438 | w.WriteHeader(http.StatusOK) |
| 439 | fmt.Fprintf(w, output) |
| 440 | }) |
| 441 | } |