blob: 5cff62226edc068bb028ad3ca8de5e2255d318b6 [file] [log] [blame]
Jon Perritt4a5c8492015-02-03 13:13:59 -07001package stacks
2
3import (
4 "testing"
5
jrperritt8ce5e282016-04-13 14:31:01 -05006 "github.com/gophercloud/gophercloud"
Jon Perritt27249f42016-02-18 10:35:59 -06007 "github.com/gophercloud/gophercloud/pagination"
8 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perritt4a5c8492015-02-03 13:13:59 -070010)
11
12func TestCreateStack(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 HandleCreateSuccessfully(t, CreateOutput)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050016 template := new(Template)
17 template.Bin = []byte(`
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 }`)
28 createOpts := CreateOpts{
29 Name: "stackcreated",
30 Timeout: 60,
31 TemplateOpts: template,
Jon Perritt397ade62016-03-15 06:55:02 -050032 DisableRollback: gophercloud.Disabled,
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050033 }
34 actual, err := Create(fake.ServiceClient(), createOpts).Extract()
35 th.AssertNoErr(t, err)
36
37 expected := CreateExpected
38 th.AssertDeepEquals(t, expected, actual)
39}
40
Jon Perritt9741dd92015-02-04 12:05:47 -070041func TestAdoptStack(t *testing.T) {
42 th.SetupHTTP()
43 defer th.TeardownHTTP()
44 HandleCreateSuccessfully(t, CreateOutput)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050045 template := new(Template)
46 template.Bin = []byte(`
47{
48 "stack_name": "postman_stack",
49 "template": {
50 "heat_template_version": "2013-05-23",
51 "description": "Simple template to test heat commands",
52 "parameters": {
53 "flavor": {
54 "default": "m1.tiny",
55 "type": "string"
56 }
57 },
58 "resources": {
59 "hello_world": {
60 "type":"OS::Nova::Server",
61 "properties": {
62 "key_name": "heat_key",
63 "flavor": {
64 "get_param": "flavor"
65 },
66 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
67 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
68 }
69 }
70 }
71 }
72}`)
73 adoptOpts := AdoptOpts{
74 AdoptStackData: `{environment{parameters{}}}`,
75 Name: "stackcreated",
76 Timeout: 60,
77 TemplateOpts: template,
Jon Perritt397ade62016-03-15 06:55:02 -050078 DisableRollback: gophercloud.Disabled,
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050079 }
80 actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
81 th.AssertNoErr(t, err)
82
83 expected := CreateExpected
84 th.AssertDeepEquals(t, expected, actual)
85}
86
Jon Perritt9cd3d382015-02-04 15:49:41 -070087func TestListStack(t *testing.T) {
88 th.SetupHTTP()
89 defer th.TeardownHTTP()
90 HandleListSuccessfully(t, FullListOutput)
91
92 count := 0
93 err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
94 count++
95 actual, err := ExtractStacks(page)
96 th.AssertNoErr(t, err)
97
98 th.CheckDeepEquals(t, ListExpected, actual)
99
100 return true, nil
101 })
102 th.AssertNoErr(t, err)
103 th.CheckEquals(t, count, 1)
104}
Jon Perritt7726e492015-02-04 17:54:28 -0700105
106func TestGetStack(t *testing.T) {
107 th.SetupHTTP()
108 defer th.TeardownHTTP()
109 HandleGetSuccessfully(t, GetOutput)
110
111 actual, err := Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract()
112 th.AssertNoErr(t, err)
113
114 expected := GetExpected
115 th.AssertDeepEquals(t, expected, actual)
116}
117
118func TestUpdateStack(t *testing.T) {
119 th.SetupHTTP()
120 defer th.TeardownHTTP()
121 HandleUpdateSuccessfully(t)
122
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500123 template := new(Template)
124 template.Bin = []byte(`
125 {
126 "heat_template_version": "2013-05-23",
127 "description": "Simple template to test heat commands",
128 "parameters": {
129 "flavor": {
130 "default": "m1.tiny",
131 "type": "string"
132 }
133 }
134 }`)
135 updateOpts := UpdateOpts{
136 TemplateOpts: template,
137 }
138 err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr()
139 th.AssertNoErr(t, err)
140}
141
Jon Perritta433dd92015-02-04 18:04:13 -0700142func TestDeleteStack(t *testing.T) {
143 th.SetupHTTP()
144 defer th.TeardownHTTP()
145 HandleDeleteSuccessfully(t)
146
147 err := Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr()
148 th.AssertNoErr(t, err)
149}
Jon Perritt37f97742015-02-04 18:55:05 -0700150
151func TestPreviewStack(t *testing.T) {
152 th.SetupHTTP()
153 defer th.TeardownHTTP()
154 HandlePreviewSuccessfully(t, GetOutput)
155
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500156 template := new(Template)
157 template.Bin = []byte(`
158 {
159 "heat_template_version": "2013-05-23",
160 "description": "Simple template to test heat commands",
161 "parameters": {
162 "flavor": {
163 "default": "m1.tiny",
164 "type": "string"
165 }
166 }
167 }`)
168 previewOpts := PreviewOpts{
169 Name: "stackcreated",
170 Timeout: 60,
171 TemplateOpts: template,
Jon Perritt397ade62016-03-15 06:55:02 -0500172 DisableRollback: gophercloud.Disabled,
Pratik Mallya5fddb2a2015-09-14 14:04:49 -0500173 }
174 actual, err := Preview(fake.ServiceClient(), previewOpts).Extract()
175 th.AssertNoErr(t, err)
176
177 expected := PreviewExpected
178 th.AssertDeepEquals(t, expected, actual)
179}
180
Pratik Mallya827c03e2015-09-17 00:10:47 -0500181func TestAbandonStack(t *testing.T) {
182 th.SetupHTTP()
183 defer th.TeardownHTTP()
184 HandleAbandonSuccessfully(t, AbandonOutput)
185
186 actual, err := Abandon(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c8").Extract()
187 th.AssertNoErr(t, err)
188
189 expected := AbandonExpected
190 th.AssertDeepEquals(t, expected, actual)
191}