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