blob: fa9b3016f5157e346c3171c3bd63d5ed8adf2bd9 [file] [log] [blame]
Jon Perrittf799b942015-02-09 11:23:28 -07001package stacktemplates
2
3import (
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 Mallya827c03e2015-09-17 00:10:47 -050013var 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 Perrittf799b942015-02-09 11:23:28 -070014
15// GetOutput represents the response body from a Get request.
16const 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 Mallya827c03e2015-09-17 00:10:47 -050034 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743"
Jon Perrittf799b942015-02-09 11:23:28 -070035 }
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.
42func 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 Perritt8ade4322015-02-09 11:34:59 -070054// ValidateExpected represents the expected object from a Validate request.
Jon Perrittf799b942015-02-09 11:23:28 -070055var 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 Perritt8ade4322015-02-09 11:34:59 -070068// ValidateOutput represents the response body from a Validate request.
Jon Perrittf799b942015-02-09 11:23:28 -070069const 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.
85func 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}