blob: 1606d98299ce3e383dd1ad4df0b3ecdef10deeb8 [file] [log] [blame]
Jon Perritt4a5c8492015-02-03 13:13:59 -07001package stacks
2
3import (
4 "testing"
5
Jon Perritt9cd3d382015-02-04 15:49:41 -07006 "github.com/rackspace/gophercloud/pagination"
Jon Perritt4a5c8492015-02-03 13:13:59 -07007 th "github.com/rackspace/gophercloud/testhelper"
8 fake "github.com/rackspace/gophercloud/testhelper/client"
9)
10
11func TestCreateStack(t *testing.T) {
12 th.SetupHTTP()
13 defer th.TeardownHTTP()
14 HandleCreateSuccessfully(t, CreateOutput)
15
16 createOpts := CreateOpts{
17 Name: "stackcreated",
18 Timeout: 60,
19 Template: `
20 {
21 "stack_name": "postman_stack",
22 "template": {
23 "heat_template_version": "2013-05-23",
24 "description": "Simple template to test heat commands",
25 "parameters": {
26 "flavor": {
27 "default": "m1.tiny",
28 "type": "string"
29 }
30 },
31 "resources": {
32 "hello_world": {
33 "type":"OS::Nova::Server",
34 "properties": {
35 "key_name": "heat_key",
36 "flavor": {
37 "get_param": "flavor"
38 },
39 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
40 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
41 }
42 }
43 }
44 }
45 }`,
46 DisableRollback: Disable,
47 }
48 actual, err := Create(fake.ServiceClient(), createOpts).Extract()
49 th.AssertNoErr(t, err)
50
51 expected := CreateExpected
52 th.AssertDeepEquals(t, expected, actual)
53}
Jon Perritt9741dd92015-02-04 12:05:47 -070054
55func TestAdoptStack(t *testing.T) {
56 th.SetupHTTP()
57 defer th.TeardownHTTP()
58 HandleCreateSuccessfully(t, CreateOutput)
59
60 adoptOpts := AdoptOpts{
61 AdoptStackData: `{environment{parameters{}}}`,
62 Name: "stackcreated",
63 Timeout: 60,
64 Template: `
65 {
66 "stack_name": "postman_stack",
67 "template": {
68 "heat_template_version": "2013-05-23",
69 "description": "Simple template to test heat commands",
70 "parameters": {
71 "flavor": {
72 "default": "m1.tiny",
73 "type": "string"
74 }
75 },
76 "resources": {
77 "hello_world": {
78 "type":"OS::Nova::Server",
79 "properties": {
80 "key_name": "heat_key",
81 "flavor": {
82 "get_param": "flavor"
83 },
84 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
85 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
86 }
87 }
88 }
89 }
90 }`,
91 DisableRollback: Disable,
92 }
93 actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
94 th.AssertNoErr(t, err)
95
96 expected := CreateExpected
97 th.AssertDeepEquals(t, expected, actual)
98}
Jon Perritt9cd3d382015-02-04 15:49:41 -070099
100func TestListStack(t *testing.T) {
101 th.SetupHTTP()
102 defer th.TeardownHTTP()
103 HandleListSuccessfully(t, FullListOutput)
104
105 count := 0
106 err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
107 count++
108 actual, err := ExtractStacks(page)
109 th.AssertNoErr(t, err)
110
111 th.CheckDeepEquals(t, ListExpected, actual)
112
113 return true, nil
114 })
115 th.AssertNoErr(t, err)
116 th.CheckEquals(t, count, 1)
117}
Jon Perritt7726e492015-02-04 17:54:28 -0700118
119func TestGetStack(t *testing.T) {
120 th.SetupHTTP()
121 defer th.TeardownHTTP()
122 HandleGetSuccessfully(t, GetOutput)
123
124 actual, err := Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract()
125 th.AssertNoErr(t, err)
126
127 expected := GetExpected
128 th.AssertDeepEquals(t, expected, actual)
129}
130
131func TestUpdateStack(t *testing.T) {
132 th.SetupHTTP()
133 defer th.TeardownHTTP()
134 HandleUpdateSuccessfully(t)
135
136 updateOpts := UpdateOpts{
137 Template: `
138 {
139 "heat_template_version": "2013-05-23",
140 "description": "Simple template to test heat commands",
141 "parameters": {
142 "flavor": {
143 "default": "m1.tiny",
144 "type": "string"
145 }
146 },
147 "resources": {
148 "hello_world": {
149 "type":"OS::Nova::Server",
150 "properties": {
151 "key_name": "heat_key",
152 "flavor": {
153 "get_param": "flavor"
154 },
155 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
156 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
157 }
158 }
159 }
160 }`,
161 }
162 err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr()
163 th.AssertNoErr(t, err)
164}
Jon Perritta433dd92015-02-04 18:04:13 -0700165
166func TestDeleteStack(t *testing.T) {
167 th.SetupHTTP()
168 defer th.TeardownHTTP()
169 HandleDeleteSuccessfully(t)
170
171 err := Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr()
172 th.AssertNoErr(t, err)
173}
Jon Perritt37f97742015-02-04 18:55:05 -0700174
175func TestPreviewStack(t *testing.T) {
176 th.SetupHTTP()
177 defer th.TeardownHTTP()
178 HandlePreviewSuccessfully(t, GetOutput)
179
180 previewOpts := PreviewOpts{
181 Name: "stackcreated",
182 Timeout: 60,
183 Template: `
184 {
185 "stack_name": "postman_stack",
186 "template": {
187 "heat_template_version": "2013-05-23",
188 "description": "Simple template to test heat commands",
189 "parameters": {
190 "flavor": {
191 "default": "m1.tiny",
192 "type": "string"
193 }
194 },
195 "resources": {
196 "hello_world": {
197 "type":"OS::Nova::Server",
198 "properties": {
199 "key_name": "heat_key",
200 "flavor": {
201 "get_param": "flavor"
202 },
203 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
204 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
205 }
206 }
207 }
208 }
209 }`,
210 DisableRollback: Disable,
211 }
212 actual, err := Preview(fake.ServiceClient(), previewOpts).Extract()
213 th.AssertNoErr(t, err)
214
215 expected := PreviewExpected
216 th.AssertDeepEquals(t, expected, actual)
217}
Pratik Mallya827c03e2015-09-17 00:10:47 -0500218
219func TestAbandonStack(t *testing.T) {
220 th.SetupHTTP()
221 defer th.TeardownHTTP()
222 HandleAbandonSuccessfully(t, AbandonOutput)
223
224 actual, err := Abandon(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c8").Extract()
225 th.AssertNoErr(t, err)
226
227 expected := AbandonExpected
228 th.AssertDeepEquals(t, expected, actual)
229}