Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 1 | package stacktemplates |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | // GetExpected represents the expected object from a Get request. |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 13 | var GetExpected = "{\n \"description\": \"Simple template to test heat commands\",\n \"heat_template_version\": \"2013-05-23\",\n \"parameters\": {\n \"flavor\": {\n \"default\": \"m1.tiny\",\n \"type\": \"string\"\n }\n },\n \"resources\": {\n \"hello_world\": {\n \"properties\": {\n \"flavor\": {\n \"get_param\": \"flavor\"\n },\n \"image\": \"ad091b52-742f-469e-8f3c-fd81cadf0743\",\n \"key_name\": \"heat_key\"\n },\n \"type\": \"OS::Nova::Server\"\n }\n }\n}" |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 14 | |
| 15 | // GetOutput represents the response body from a Get request. |
| 16 | const GetOutput = ` |
| 17 | { |
| 18 | "heat_template_version": "2013-05-23", |
| 19 | "description": "Simple template to test heat commands", |
| 20 | "parameters": { |
| 21 | "flavor": { |
| 22 | "default": "m1.tiny", |
| 23 | "type": "string" |
| 24 | } |
| 25 | }, |
| 26 | "resources": { |
| 27 | "hello_world": { |
| 28 | "type": "OS::Nova::Server", |
| 29 | "properties": { |
| 30 | "key_name": "heat_key", |
| 31 | "flavor": { |
| 32 | "get_param": "flavor" |
| 33 | }, |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 34 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743" |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | } |
| 38 | }` |
| 39 | |
| 40 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template` |
| 41 | // on the test handler mux that responds with a `Get` response. |
| 42 | func HandleGetSuccessfully(t *testing.T, output string) { |
| 43 | th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template", func(w http.ResponseWriter, r *http.Request) { |
| 44 | th.TestMethod(t, r, "GET") |
| 45 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 46 | th.TestHeader(t, r, "Accept", "application/json") |
| 47 | |
| 48 | w.Header().Set("Content-Type", "application/json") |
| 49 | w.WriteHeader(http.StatusOK) |
| 50 | fmt.Fprintf(w, output) |
| 51 | }) |
| 52 | } |
| 53 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame] | 54 | // ValidateExpected represents the expected object from a Validate request. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 55 | var ValidateExpected = &ValidatedTemplate{ |
| 56 | Description: "Simple template to test heat commands", |
| 57 | Parameters: map[string]interface{}{ |
| 58 | "flavor": map[string]interface{}{ |
| 59 | "Default": "m1.tiny", |
| 60 | "Type": "String", |
| 61 | "NoEcho": "false", |
| 62 | "Description": "", |
| 63 | "Label": "flavor", |
| 64 | }, |
| 65 | }, |
| 66 | } |
| 67 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame] | 68 | // ValidateOutput represents the response body from a Validate request. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 69 | const ValidateOutput = ` |
| 70 | { |
| 71 | "Description": "Simple template to test heat commands", |
| 72 | "Parameters": { |
| 73 | "flavor": { |
| 74 | "Default": "m1.tiny", |
| 75 | "Type": "String", |
| 76 | "NoEcho": "false", |
| 77 | "Description": "", |
| 78 | "Label": "flavor" |
| 79 | } |
| 80 | } |
| 81 | }` |
| 82 | |
| 83 | // HandleValidateSuccessfully creates an HTTP handler at `/validate` |
| 84 | // on the test handler mux that responds with a `Validate` response. |
| 85 | func HandleValidateSuccessfully(t *testing.T, output string) { |
| 86 | th.Mux.HandleFunc("/validate", func(w http.ResponseWriter, r *http.Request) { |
| 87 | th.TestMethod(t, r, "POST") |
| 88 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 89 | th.TestHeader(t, r, "Accept", "application/json") |
| 90 | |
| 91 | w.Header().Set("Content-Type", "application/json") |
| 92 | w.WriteHeader(http.StatusOK) |
| 93 | fmt.Fprintf(w, output) |
| 94 | }) |
| 95 | } |