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