blob: dc354ec2cfd83f3e15327598946414d1dc4e8314 [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.
13var GetExpected = &Template{
14 Description: "Simple template to test heat commands",
15 HeatTemplateVersion: "2013-05-23",
16 Parameters: map[string]interface{}{
17 "flavor": map[string]interface{}{
18 "default": "m1.tiny",
19 "type": "string",
20 },
21 },
22 Resources: map[string]interface{}{
23 "hello_world": map[string]interface{}{
24 "type": "OS::Nova::Server",
25 "properties": map[string]interface{}{
26 "key_name": "heat_key",
27 "flavor": map[string]interface{}{
28 "get_param": "flavor",
29 },
30 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
31 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n",
32 },
33 },
34 },
35}
36
37// GetOutput represents the response body from a Get request.
38const GetOutput = `
39{
40 "heat_template_version": "2013-05-23",
41 "description": "Simple template to test heat commands",
42 "parameters": {
43 "flavor": {
44 "default": "m1.tiny",
45 "type": "string"
46 }
47 },
48 "resources": {
49 "hello_world": {
50 "type": "OS::Nova::Server",
51 "properties": {
52 "key_name": "heat_key",
53 "flavor": {
54 "get_param": "flavor"
55 },
56 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
57 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
58 }
59 }
60 }
61}`
62
63// HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template`
64// on the test handler mux that responds with a `Get` response.
65func HandleGetSuccessfully(t *testing.T, output string) {
66 th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template", func(w http.ResponseWriter, r *http.Request) {
67 th.TestMethod(t, r, "GET")
68 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
69 th.TestHeader(t, r, "Accept", "application/json")
70
71 w.Header().Set("Content-Type", "application/json")
72 w.WriteHeader(http.StatusOK)
73 fmt.Fprintf(w, output)
74 })
75}
76
77var ValidateExpected = &ValidatedTemplate{
78 Description: "Simple template to test heat commands",
79 Parameters: map[string]interface{}{
80 "flavor": map[string]interface{}{
81 "Default": "m1.tiny",
82 "Type": "String",
83 "NoEcho": "false",
84 "Description": "",
85 "Label": "flavor",
86 },
87 },
88}
89
90const ValidateOutput = `
91{
92 "Description": "Simple template to test heat commands",
93 "Parameters": {
94 "flavor": {
95 "Default": "m1.tiny",
96 "Type": "String",
97 "NoEcho": "false",
98 "Description": "",
99 "Label": "flavor"
100 }
101 }
102}`
103
104// HandleValidateSuccessfully creates an HTTP handler at `/validate`
105// on the test handler mux that responds with a `Validate` response.
106func HandleValidateSuccessfully(t *testing.T, output string) {
107 th.Mux.HandleFunc("/validate", func(w http.ResponseWriter, r *http.Request) {
108 th.TestMethod(t, r, "POST")
109 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
110 th.TestHeader(t, r, "Accept", "application/json")
111
112 w.Header().Set("Content-Type", "application/json")
113 w.WriteHeader(http.StatusOK)
114 fmt.Fprintf(w, output)
115 })
116}