blob: dc018c1bcecb1673dcb6939ef26921f08de6affe [file] [log] [blame]
Jon Perritt4a5c8492015-02-03 13:13:59 -07001package stacks
2
3import (
4 "testing"
5
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud/pagination"
7 th "github.com/gophercloud/gophercloud/testhelper"
8 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perritt4a5c8492015-02-03 13:13:59 -07009)
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
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050055func TestCreateStackNewTemplateFormat(t *testing.T) {
56 th.SetupHTTP()
57 defer th.TeardownHTTP()
58 HandleCreateSuccessfully(t, CreateOutput)
59 template := new(Template)
60 template.Bin = []byte(`
61 {
62 "heat_template_version": "2013-05-23",
63 "description": "Simple template to test heat commands",
64 "parameters": {
65 "flavor": {
66 "default": "m1.tiny",
67 "type": "string"
68 }
69 }
70 }`)
71 createOpts := CreateOpts{
72 Name: "stackcreated",
73 Timeout: 60,
74 TemplateOpts: template,
75 DisableRollback: Disable,
76 }
77 actual, err := Create(fake.ServiceClient(), createOpts).Extract()
78 th.AssertNoErr(t, err)
79
80 expected := CreateExpected
81 th.AssertDeepEquals(t, expected, actual)
82}
83
Jon Perritt9741dd92015-02-04 12:05:47 -070084func TestAdoptStack(t *testing.T) {
85 th.SetupHTTP()
86 defer th.TeardownHTTP()
87 HandleCreateSuccessfully(t, CreateOutput)
88
89 adoptOpts := AdoptOpts{
90 AdoptStackData: `{environment{parameters{}}}`,
91 Name: "stackcreated",
92 Timeout: 60,
93 Template: `
94 {
95 "stack_name": "postman_stack",
96 "template": {
97 "heat_template_version": "2013-05-23",
98 "description": "Simple template to test heat commands",
99 "parameters": {
100 "flavor": {
101 "default": "m1.tiny",
102 "type": "string"
103 }
104 },
105 "resources": {
106 "hello_world": {
107 "type":"OS::Nova::Server",
108 "properties": {
109 "key_name": "heat_key",
110 "flavor": {
111 "get_param": "flavor"
112 },
113 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
114 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
115 }
116 }
117 }
118 }
119 }`,
120 DisableRollback: Disable,
121 }
122 actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
123 th.AssertNoErr(t, err)
124
125 expected := CreateExpected
126 th.AssertDeepEquals(t, expected, actual)
127}
Jon Perritt9cd3d382015-02-04 15:49:41 -0700128
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500129func TestAdoptStackNewTemplateFormat(t *testing.T) {
130 th.SetupHTTP()
131 defer th.TeardownHTTP()
132 HandleCreateSuccessfully(t, CreateOutput)
133 template := new(Template)
134 template.Bin = []byte(`
135{
136 "stack_name": "postman_stack",
137 "template": {
138 "heat_template_version": "2013-05-23",
139 "description": "Simple template to test heat commands",
140 "parameters": {
141 "flavor": {
142 "default": "m1.tiny",
143 "type": "string"
144 }
145 },
146 "resources": {
147 "hello_world": {
148 "type":"OS::Nova::Server",
149 "properties": {
150 "key_name": "heat_key",
151 "flavor": {
152 "get_param": "flavor"
153 },
154 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
155 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
156 }
157 }
158 }
159 }
160}`)
161 adoptOpts := AdoptOpts{
162 AdoptStackData: `{environment{parameters{}}}`,
163 Name: "stackcreated",
164 Timeout: 60,
165 TemplateOpts: template,
166 DisableRollback: Disable,
167 }
168 actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
169 th.AssertNoErr(t, err)
170
171 expected := CreateExpected
172 th.AssertDeepEquals(t, expected, actual)
173}
174
Jon Perritt9cd3d382015-02-04 15:49:41 -0700175func TestListStack(t *testing.T) {
176 th.SetupHTTP()
177 defer th.TeardownHTTP()
178 HandleListSuccessfully(t, FullListOutput)
179
180 count := 0
181 err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
182 count++
183 actual, err := ExtractStacks(page)
184 th.AssertNoErr(t, err)
185
186 th.CheckDeepEquals(t, ListExpected, actual)
187
188 return true, nil
189 })
190 th.AssertNoErr(t, err)
191 th.CheckEquals(t, count, 1)
192}
Jon Perritt7726e492015-02-04 17:54:28 -0700193
194func TestGetStack(t *testing.T) {
195 th.SetupHTTP()
196 defer th.TeardownHTTP()
197 HandleGetSuccessfully(t, GetOutput)
198
199 actual, err := Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract()
200 th.AssertNoErr(t, err)
201
202 expected := GetExpected
203 th.AssertDeepEquals(t, expected, actual)
204}
205
206func TestUpdateStack(t *testing.T) {
207 th.SetupHTTP()
208 defer th.TeardownHTTP()
209 HandleUpdateSuccessfully(t)
210
211 updateOpts := UpdateOpts{
212 Template: `
213 {
214 "heat_template_version": "2013-05-23",
215 "description": "Simple template to test heat commands",
216 "parameters": {
217 "flavor": {
218 "default": "m1.tiny",
219 "type": "string"
220 }
221 },
222 "resources": {
223 "hello_world": {
224 "type":"OS::Nova::Server",
225 "properties": {
226 "key_name": "heat_key",
227 "flavor": {
228 "get_param": "flavor"
229 },
230 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
231 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
232 }
233 }
234 }
235 }`,
236 }
237 err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr()
238 th.AssertNoErr(t, err)
239}
Jon Perritta433dd92015-02-04 18:04:13 -0700240
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500241func TestUpdateStackNewTemplateFormat(t *testing.T) {
242 th.SetupHTTP()
243 defer th.TeardownHTTP()
244 HandleUpdateSuccessfully(t)
245
246 template := new(Template)
247 template.Bin = []byte(`
248 {
249 "heat_template_version": "2013-05-23",
250 "description": "Simple template to test heat commands",
251 "parameters": {
252 "flavor": {
253 "default": "m1.tiny",
254 "type": "string"
255 }
256 }
257 }`)
258 updateOpts := UpdateOpts{
259 TemplateOpts: template,
260 }
261 err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr()
262 th.AssertNoErr(t, err)
263}
264
Jon Perritta433dd92015-02-04 18:04:13 -0700265func TestDeleteStack(t *testing.T) {
266 th.SetupHTTP()
267 defer th.TeardownHTTP()
268 HandleDeleteSuccessfully(t)
269
270 err := Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr()
271 th.AssertNoErr(t, err)
272}
Jon Perritt37f97742015-02-04 18:55:05 -0700273
274func TestPreviewStack(t *testing.T) {
275 th.SetupHTTP()
276 defer th.TeardownHTTP()
277 HandlePreviewSuccessfully(t, GetOutput)
278
279 previewOpts := PreviewOpts{
280 Name: "stackcreated",
281 Timeout: 60,
282 Template: `
283 {
284 "stack_name": "postman_stack",
285 "template": {
286 "heat_template_version": "2013-05-23",
287 "description": "Simple template to test heat commands",
288 "parameters": {
289 "flavor": {
290 "default": "m1.tiny",
291 "type": "string"
292 }
293 },
294 "resources": {
295 "hello_world": {
296 "type":"OS::Nova::Server",
297 "properties": {
298 "key_name": "heat_key",
299 "flavor": {
300 "get_param": "flavor"
301 },
302 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
303 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
304 }
305 }
306 }
307 }
308 }`,
309 DisableRollback: Disable,
310 }
311 actual, err := Preview(fake.ServiceClient(), previewOpts).Extract()
312 th.AssertNoErr(t, err)
313
314 expected := PreviewExpected
315 th.AssertDeepEquals(t, expected, actual)
316}
Pratik Mallya827c03e2015-09-17 00:10:47 -0500317
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500318func TestPreviewStackNewTemplateFormat(t *testing.T) {
319 th.SetupHTTP()
320 defer th.TeardownHTTP()
321 HandlePreviewSuccessfully(t, GetOutput)
322
323 template := new(Template)
324 template.Bin = []byte(`
325 {
326 "heat_template_version": "2013-05-23",
327 "description": "Simple template to test heat commands",
328 "parameters": {
329 "flavor": {
330 "default": "m1.tiny",
331 "type": "string"
332 }
333 }
334 }`)
335 previewOpts := PreviewOpts{
336 Name: "stackcreated",
337 Timeout: 60,
338 TemplateOpts: template,
339 DisableRollback: Disable,
340 }
341 actual, err := Preview(fake.ServiceClient(), previewOpts).Extract()
342 th.AssertNoErr(t, err)
343
344 expected := PreviewExpected
345 th.AssertDeepEquals(t, expected, actual)
346}
347
Pratik Mallya827c03e2015-09-17 00:10:47 -0500348func TestAbandonStack(t *testing.T) {
349 th.SetupHTTP()
350 defer th.TeardownHTTP()
351 HandleAbandonSuccessfully(t, AbandonOutput)
352
353 actual, err := Abandon(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c8").Extract()
354 th.AssertNoErr(t, err)
355
356 expected := AbandonExpected
357 th.AssertDeepEquals(t, expected, actual)
358}