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