cfndk 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'CFnDK', type: :aruba do
4
+ before(:each) { setup_aruba }
5
+ before(:each) { set_environment_variable('AWS_REGION', ENV['AWS_REGION']) }
6
+ before(:each) { set_environment_variable('AWS_PROFILE', ENV['AWS_PROFILE']) }
7
+
8
+ describe 'bin/cfndk' do
9
+ describe 'report', report: true do
10
+ context 'without cfndk.yml' do
11
+ before(:each) { run_command('cfndk report') }
12
+ it 'displays file does not exist error and status code = 1' do
13
+ aggregate_failures do
14
+ expect(last_command_started).to have_exit_status(1)
15
+ expect(last_command_started).to have_output(/ERROR File does not exist./)
16
+ end
17
+ end
18
+ end
19
+ context 'with cfndk2.yml' do
20
+ context 'when -c cfndk2.yml and empty keyparis and stacks' do
21
+ yaml = <<-"YAML"
22
+ keypairs:
23
+ stacks:
24
+ YAML
25
+ before(:each) { write_file('cfndk2.yml', yaml) }
26
+ before(:each) { run_command('cfndk report -c=cfndk2.yml') }
27
+ it 'displays empty stacks and keypairs report' do
28
+ aggregate_failures do
29
+ expect(last_command_started).to be_successfully_executed
30
+ expect(last_command_started).to have_output(/INFO report.../)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ context 'with cfndk.yml' do
36
+ context 'when cfndk.yml is empty' do
37
+ before(:each) { touch('cfndk.yml') }
38
+ before(:each) { run_command('cfndk report') }
39
+ it 'displays File is empty error and status code = 1' do
40
+ aggregate_failures do
41
+ expect(last_command_started).to have_exit_status(1)
42
+ expect(last_command_started).to have_output(/ERROR File is empty./)
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'with empty keypairs and stacks' do
48
+ yaml = <<-"YAML"
49
+ keypairs:
50
+ stacks:
51
+ YAML
52
+ before(:each) { write_file('cfndk.yml', yaml) }
53
+ before(:each) { run_command('cfndk report') }
54
+ it 'displays empty stacks and keypairs report' do
55
+ aggregate_failures do
56
+ expect(last_command_started).to be_successfully_executed
57
+ expect(last_command_started).to have_output(/INFO report.../)
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'with keypairs and stacks' do
63
+ yaml = <<-"YAML"
64
+ keypairs:
65
+ Key1:
66
+ Key2:
67
+ stacks:
68
+ Test:
69
+ template_file: vpc.yaml
70
+ parameter_input: vpc.json
71
+ timeout_in_minutes: 2
72
+ Test2:
73
+ template_file: sg.yaml
74
+ parameter_input: sg.json
75
+ depends:
76
+ - Test
77
+ YAML
78
+ context 'without UUID' do
79
+ before(:each) { write_file('cfndk.yml', yaml) }
80
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
81
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
82
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
83
+ before(:each) { copy('%/sg.json', 'sg.json') }
84
+ before(:each) { run_command_and_stop('cfndk create') }
85
+ context 'without option' do
86
+ before(:each) { run_command('cfndk report') }
87
+ it 'displays stacks report' do
88
+ aggregate_failures do
89
+ expect(last_command_started).to be_successfully_executed
90
+ expect(last_command_started).to have_output(/INFO stack: Test$/)
91
+ expect(last_command_started).to have_output(/INFO stack: Test2$/)
92
+ end
93
+ end
94
+ end
95
+ context 'when --stack-names Test2' do
96
+ before(:each) { run_command('cfndk report --stack-names Test2') }
97
+ it 'displays stacks report' do
98
+ aggregate_failures do
99
+ expect(last_command_started).to be_successfully_executed
100
+ expect(last_command_started).not_to have_output(/INFO stack: Test$/)
101
+ expect(last_command_started).to have_output(/INFO stack: Test2$/)
102
+ end
103
+ end
104
+ end
105
+ context 'when --stack-names Test3' do
106
+ before(:each) { run_command('cfndk report --stack-names Test3') }
107
+ it 'displays stacks report' do
108
+ aggregate_failures do
109
+ expect(last_command_started).to be_successfully_executed
110
+ expect(last_command_started).not_to have_output(/INFO stack: Test$/)
111
+ expect(last_command_started).not_to have_output(/INFO stack: Test2$/)
112
+ expect(last_command_started).not_to have_output(/INFO stack: Test3$/)
113
+ end
114
+ end
115
+ end
116
+ after(:each) { run_command('cfndk destroy -f') }
117
+ end
118
+ context 'with UUID' do
119
+ before(:each) { write_file('cfndk.yml', yaml) }
120
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
121
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
122
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
123
+ before(:each) { copy('%/sg.json', 'sg.json') }
124
+ before(:each) { run_command_and_stop('cfndk create -u 38437346-c75c-47c5-83b4-d504f85e275b') }
125
+ context 'without option' do
126
+ before(:each) { run_command('cfndk report -u 38437346-c75c-47c5-83b4-d504f85e275b') }
127
+ it 'displays stacks report' do
128
+ aggregate_failures do
129
+ expect(last_command_started).to be_successfully_executed
130
+ expect(last_command_started).to have_output(/INFO stack: Test-38437346-c75c-47c5-83b4-d504f85e275b$/)
131
+ expect(last_command_started).to have_output(/INFO stack: Test2-38437346-c75c-47c5-83b4-d504f85e275b$/)
132
+ end
133
+ end
134
+ end
135
+ context 'when --stack-names Test2' do
136
+ before(:each) { run_command('cfndk report -u 38437346-c75c-47c5-83b4-d504f85e275b --stack-names Test2') }
137
+ it 'displays stacks report' do
138
+ aggregate_failures do
139
+ expect(last_command_started).to be_successfully_executed
140
+ expect(last_command_started).not_to have_output(/INFO stack: Test-38437346-c75c-47c5-83b4-d504f85e275b$/)
141
+ expect(last_command_started).to have_output(/INFO stack: Test2-38437346-c75c-47c5-83b4-d504f85e275b$/)
142
+ end
143
+ end
144
+ end
145
+ context 'when --stack-names Test3' do
146
+ before(:each) { run_command('cfndk report -u 38437346-c75c-47c5-83b4-d504f85e275b --stack-names Test3') }
147
+ it 'displays stacks report' do
148
+ aggregate_failures do
149
+ expect(last_command_started).to be_successfully_executed
150
+ expect(last_command_started).not_to have_output(/INFO stack: Test-/)
151
+ expect(last_command_started).not_to have_output(/INFO stack: Test2-/)
152
+ expect(last_command_started).not_to have_output(/INFO stack: Test3-/)
153
+ end
154
+ end
155
+ end
156
+ after(:each) { run_command('cfndk destroy -f -u 38437346-c75c-47c5-83b4-d504f85e275b') }
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'CFnDK', type: :aruba do
4
+ before(:each) { prepend_environment_variable('AWS_REGION', ENV['AWS_REGION']) }
5
+ before(:each) { prepend_environment_variable('AWS_PROFILE', ENV['AWS_PROFILE']) }
6
+ describe 'bin/cfndk' do
7
+ before(:each) { setup_aruba }
8
+ let(:file) { 'cfndk.yml' }
9
+ let(:file2) { 'cfndk2.yml' }
10
+ let(:pem) { 'test.pem' }
11
+ let(:uuid) { '38437346-c75c-47c5-83b4-d504f85e275b' }
12
+
13
+ context 'without command', help: true do
14
+ before(:each) { run_command('cfndk') }
15
+ it 'displays help and status code = 2' do
16
+ aggregate_failures do
17
+ expect(last_command_started).to have_exit_status(2)
18
+ end
19
+ end
20
+ end
21
+
22
+ context 'invalid command' do
23
+ before(:each) { run_command('cfndk sstack') }
24
+ it 'displays help and status code = 1' do
25
+ aggregate_failures do
26
+ expect(last_command_started).to have_exit_status(1)
27
+ expect(last_command_started).to have_output(/Could not find command "sstack"\./)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'version', help: true do
33
+ before(:each) { run_command('cfndk version') }
34
+ it 'displays version' do
35
+ aggregate_failures do
36
+ expect(last_command_started).to be_successfully_executed
37
+ expect(last_command_started).to have_output(/0.1.0/)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'generate-uuid', uuid: true do
43
+ before(:each) { run_command('cfndk generate-uuid') }
44
+ it 'displays UUID' do
45
+ aggregate_failures do
46
+ expect(last_command_started).to be_successfully_executed
47
+ expect(last_command_started).to have_output(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe 'help', help: true do
53
+ context 'without subcommand' do
54
+ before(:each) { run_command('cfndk help') }
55
+ it 'displays help and status code = 2' do
56
+ aggregate_failures do
57
+ expect(last_command_started).to have_exit_status(2)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe 'version' do
63
+ before(:each) { run_command('cfndk help version') }
64
+ it 'displays help of version and status code = 2' do
65
+ aggregate_failures do
66
+ expect(last_command_started).to have_exit_status(2)
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ describe 'init', init: true do
73
+ context 'without cfndk.yml' do
74
+ before(:each) { run_command('cfndk init') }
75
+ it do
76
+ aggregate_failures do
77
+ expect(last_command_started).to be_successfully_executed
78
+ expect(last_command_started).to have_output(/INFO init\.\.\..+INFO create .+cfndk.yml$/m)
79
+ expect('cfndk.yml').to be_an_existing_file
80
+ expect('web/web.yaml').to be_an_existing_file
81
+ expect('web/prod.json').to be_an_existing_file
82
+ expect('network/network.yaml').to be_an_existing_file
83
+ expect('web/prod.json').to be_an_existing_file
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'with cfndk.yml' do
89
+ before(:each) { touch(file) }
90
+ before(:each) { run_command('cfndk init') }
91
+ it do
92
+ aggregate_failures do
93
+ expect(last_command_started).to have_exit_status(1)
94
+ expect(last_command_started).to have_output(/ERROR File exist./)
95
+ expect('web/web.yaml').to_not be_an_existing_file
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,1273 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'CFnDK', type: :aruba do
4
+ before(:each) { set_environment_variable('AWS_REGION', ENV['AWS_REGION']) }
5
+ before(:each) { set_environment_variable('AWS_PROFILE', ENV['AWS_PROFILE']) }
6
+ describe 'bin/cfndk' do
7
+ before(:each) { setup_aruba }
8
+ let(:file) { 'cfndk.yml' }
9
+ let(:file2) { 'cfndk2.yml' }
10
+ let(:pem) { 'test.pem' }
11
+ let(:uuid) { '38437346-c75c-47c5-83b4-d504f85e275b' }
12
+
13
+ describe 'stack' do
14
+ context 'without subcommand', help: true do
15
+ before(:each) { run_command('cfndk stack') }
16
+ it 'displays help and status code = 2' do
17
+ aggregate_failures do
18
+ expect(last_command_started).to have_exit_status(2)
19
+ end
20
+ end
21
+ end
22
+
23
+ describe 'help', help: true do
24
+ context 'without subsubcommand' do
25
+ before(:each) { run_command('cfndk stack help') }
26
+ it 'displays help and status code = 2' do
27
+ aggregate_failures do
28
+ expect(last_command_started).to have_exit_status(2)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'create', create: true do
35
+ context 'without cfndk.yml' do
36
+ before(:each) { run_command('cfndk stack create') }
37
+ it 'displays file does not exist error and status code = 1' do
38
+ aggregate_failures do
39
+ expect(last_command_started).to have_exit_status(1)
40
+ expect(last_command_started).to have_output(/ERROR File does not exist./)
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'with cfndk2.yml' do
46
+ yaml = <<-"YAML"
47
+ keypairs:
48
+ YAML
49
+ before(:each) { write_file(file2, yaml) }
50
+ context 'when -c cfndk2.yml and empty stacks' do
51
+ before(:each) { run_command("cfndk stack create -c=#{file2}") }
52
+ it 'displays empty stack log' do
53
+ aggregate_failures do
54
+ expect(last_command_started).to be_successfully_executed
55
+ expect(last_command_started).to have_output(/INFO create.../)
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'when --config-path cfndk2.yml and empty stacks' do
61
+ before(:each) { run_command("cfndk stack create --config-path=#{file2}") }
62
+ it 'displays empty stack log' do
63
+ aggregate_failures do
64
+ expect(last_command_started).to be_successfully_executed
65
+ expect(last_command_started).to have_output(/INFO create.../)
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'with cfndk.yml' do
72
+ context 'when cfndk.yml is empty' do
73
+ before(:each) { touch(file) }
74
+ before(:each) { run_command('cfndk stack create') }
75
+ it 'displays File is empty error and status code = 1' do
76
+ aggregate_failures do
77
+ expect(last_command_started).to have_exit_status(1)
78
+ expect(last_command_started).to have_output(/ERROR File is empty./)
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'with stacks:' do
84
+ context 'without stack' do
85
+ before(:each) { write_file(file, 'stacks:') }
86
+ before(:each) { run_command('cfndk stack create') }
87
+ it do
88
+ aggregate_failures do
89
+ expect(last_command_started).to be_successfully_executed
90
+ expect(last_command_started).to have_output(/INFO create.../)
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'with a stack' do
96
+ yaml = <<-"YAML"
97
+ stacks:
98
+ Test:
99
+ template_file: vpc.yaml
100
+ parameter_input: vpc.json
101
+ timeout_in_minutes: 2
102
+ YAML
103
+ before(:each) { write_file(file, yaml) }
104
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
105
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
106
+ before(:each) { run_command('cfndk stack create') }
107
+ it do
108
+ aggregate_failures do
109
+ expect(last_command_started).to be_successfully_executed
110
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
111
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
112
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
113
+ end
114
+ end
115
+ after(:each) { run_command('cfndk destroy -f') }
116
+ end
117
+ context 'with two stacks' do
118
+ yaml = <<-"YAML"
119
+ stacks:
120
+ Test:
121
+ template_file: vpc.yaml
122
+ parameter_input: vpc.json
123
+ timeout_in_minutes: 2
124
+ Test2:
125
+ template_file: sg.yaml
126
+ parameter_input: sg.json
127
+ depends:
128
+ - Test
129
+ YAML
130
+
131
+ before(:each) { write_file(file, yaml) }
132
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
133
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
134
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
135
+ before(:each) { copy('%/sg.json', 'sg.json') }
136
+ before(:each) { run_command('cfndk stack create') }
137
+ it do
138
+ aggregate_failures do
139
+ expect(last_command_started).to be_successfully_executed
140
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
141
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
142
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
143
+ expect(last_command_started).to have_output(/INFO validate stack: Test2$/)
144
+ expect(last_command_started).to have_output(/INFO creating stack: Test2$/)
145
+ expect(last_command_started).to have_output(/INFO created stack: Test2$/)
146
+ end
147
+ end
148
+ after(:each) { run_command('cfndk destroy -f') }
149
+ end
150
+ context 'when invalid dependency', dependency: true do
151
+ yaml = <<-"YAML"
152
+ stacks:
153
+ Test:
154
+ template_file: vpc.yaml
155
+ parameter_input: vpc.json
156
+ timeout_in_minutes: 2
157
+ depends:
158
+ - Test2
159
+ Test2:
160
+ template_file: sg.yaml
161
+ parameter_input: sg.json
162
+ YAML
163
+
164
+ before(:each) { write_file(file, yaml) }
165
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
166
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
167
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
168
+ before(:each) { copy('%/sg.json', 'sg.json') }
169
+ before(:each) { run_command('cfndk stack create') }
170
+ it do
171
+ aggregate_failures do
172
+ expect(last_command_started).to have_exit_status(1)
173
+ expect(last_command_started).to have_output(/ERROR stopped waiting, encountered a failure state$/)
174
+ end
175
+ end
176
+ after(:each) { run_command('cfndk destroy -f') }
177
+ end
178
+ context 'when cyclic dependency', dependency: true do
179
+ yaml = <<-"YAML"
180
+ stacks:
181
+ Test:
182
+ template_file: vpc.yaml
183
+ parameter_input: vpc.json
184
+ timeout_in_minutes: 2
185
+ depends:
186
+ - Test2
187
+ Test2:
188
+ template_file: sg.yaml
189
+ parameter_input: sg.json
190
+ depends:
191
+ - Test
192
+ YAML
193
+
194
+ before(:each) { write_file(file, yaml) }
195
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
196
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
197
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
198
+ before(:each) { copy('%/sg.json', 'sg.json') }
199
+ before(:each) { run_command('cfndk stack create') }
200
+ it do
201
+ aggregate_failures do
202
+ expect(last_command_started).to have_exit_status(1)
203
+ expect(last_command_started).to have_output(/ERROR There are cyclic dependency or stack doesn't exist. unprocessed_stack: Test,Test2$/)
204
+ end
205
+ end
206
+ after(:each) { run_command('cfndk destroy -f') }
207
+ end
208
+ context 'when requires capabilities without capabilities', capabilities: true do
209
+ yaml = <<-"YAML"
210
+ stacks:
211
+ Test:
212
+ template_file: iam.yaml
213
+ parameter_input: iam.json
214
+ timeout_in_minutes: 2
215
+ YAML
216
+
217
+ before(:each) { write_file(file, yaml) }
218
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
219
+ before(:each) { copy('%/iam.json', 'iam.json') }
220
+ before(:each) { run_command('cfndk stack create') }
221
+ it do
222
+ aggregate_failures do
223
+ expect(last_command_started).to have_exit_status(1)
224
+ expect(last_command_started).to have_output(/ERROR Requires capabilities : \[CAPABILITY_NAMED_IAM\]/)
225
+ end
226
+ end
227
+ after(:each) { run_command('cfndk destroy -f') }
228
+ end
229
+ context 'when success with capabilities', capabilities: true do
230
+ yaml = <<-"YAML"
231
+ stacks:
232
+ Test:
233
+ template_file: iam.yaml
234
+ parameter_input: iam.json
235
+ capabilities:
236
+ - CAPABILITY_NAMED_IAM
237
+ timeout_in_minutes: 3
238
+ YAML
239
+
240
+ before(:each) { write_file(file, yaml) }
241
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
242
+ before(:each) { copy('%/iam.json', 'iam.json') }
243
+ before(:each) { run_command('cfndk stack create') }
244
+ it do
245
+ aggregate_failures do
246
+ expect(last_command_started).to be_successfully_executed
247
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
248
+ end
249
+ end
250
+ after(:each) { run_command('cfndk destroy -f') }
251
+ end
252
+ context 'with UUID', uuid: true do
253
+ context 'when -u 38437346-c75c-47c5-83b4-d504f85e275b' do
254
+ yaml = <<-"YAML"
255
+ stacks:
256
+ Test:
257
+ template_file: vpc.yaml
258
+ parameter_input: vpc.json
259
+ parameters:
260
+ VpcName: sample<%= append_uuid%>
261
+ timeout_in_minutes: 2
262
+ Test2:
263
+ template_file: sg.yaml
264
+ parameter_input: sg.json
265
+ parameters:
266
+ VpcName: sample<%= append_uuid%>
267
+ depends:
268
+ - Test
269
+ YAML
270
+ before(:each) { write_file(file, yaml) }
271
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
272
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
273
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
274
+ before(:each) { copy('%/sg.json', 'sg.json') }
275
+ before(:each) { run_command("cfndk stack create -u=#{uuid}") }
276
+ it do
277
+ aggregate_failures do
278
+ expect(last_command_started).to be_successfully_executed
279
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
280
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
281
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
282
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
283
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
284
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
285
+ end
286
+ end
287
+ after(:each) { run_command("cfndk destroy -f -u=#{uuid}") }
288
+ end
289
+ context 'when env CFNDK_UUID=38437346-c75c-47c5-83b4-d504f85e275b' do
290
+ before(:each) { set_environment_variable('CFNDK_UUID', uuid) }
291
+ context 'with two stacks' do
292
+ yaml = <<-"YAML"
293
+ stacks:
294
+ Test:
295
+ template_file: vpc.yaml
296
+ parameter_input: vpc.json
297
+ parameters:
298
+ VpcName: sample<%= append_uuid%>
299
+ timeout_in_minutes: 2
300
+ Test2:
301
+ template_file: sg.yaml
302
+ parameter_input: sg.json
303
+ parameters:
304
+ VpcName: sample<%= append_uuid%>
305
+ depends:
306
+ - Test
307
+ YAML
308
+ before(:each) { write_file(file, yaml) }
309
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
310
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
311
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
312
+ before(:each) { copy('%/sg.json', 'sg.json') }
313
+ before(:each) { run_command('cfndk stack create') }
314
+ it do
315
+ aggregate_failures do
316
+ expect(last_command_started).to be_successfully_executed
317
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
318
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
319
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
320
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
321
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
322
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
323
+ end
324
+ end
325
+ after(:each) { run_command('cfndk destroy -f') }
326
+ end
327
+ context 'when --stack-names=Test' do
328
+ yaml = <<-"YAML"
329
+ stacks:
330
+ Test:
331
+ template_file: vpc.yaml
332
+ parameter_input: vpc.json
333
+ parameters:
334
+ VpcName: sample<%= append_uuid%>
335
+ timeout_in_minutes: 2
336
+ Test2:
337
+ template_file: sg.yaml
338
+ parameter_input: sg.json
339
+ parameters:
340
+ VpcName: sample<%= append_uuid%>
341
+ depends:
342
+ - Test
343
+ YAML
344
+ before(:each) { write_file(file, yaml) }
345
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
346
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
347
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
348
+ before(:each) { copy('%/sg.json', 'sg.json') }
349
+ before(:each) { run_command('cfndk stack create --stack-names=Test') }
350
+ it do
351
+ aggregate_failures do
352
+ expect(last_command_started).to be_successfully_executed
353
+ expect(last_command_started).to have_output(/INFO create.../)
354
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
355
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
356
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
357
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test2-#{uuid}$/)
358
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test2-#{uuid}$/)
359
+ expect(last_command_started).not_to have_output(/INFO created stack: Test2-#{uuid}$/)
360
+ end
361
+ end
362
+ after(:each) { run_command('cfndk destroy -f') }
363
+ end
364
+ context 'when --stack-names=Test Test2' do
365
+ yaml = <<-"YAML"
366
+ stacks:
367
+ Test:
368
+ template_file: vpc.yaml
369
+ parameter_input: vpc.json
370
+ parameters:
371
+ VpcName: sample<%= append_uuid%>
372
+ timeout_in_minutes: 2
373
+ Test2:
374
+ template_file: sg.yaml
375
+ parameter_input: sg.json
376
+ parameters:
377
+ VpcName: sample<%= append_uuid%>
378
+ depends:
379
+ - Test
380
+ Test3:
381
+ template_file: iam.yaml
382
+ parameter_input: iam.json
383
+ parameters:
384
+ WebRoleName: WebhRole<%= append_uuid%>
385
+ capabilities:
386
+ - CAPABILITY_NAMED_IAM
387
+ timeout_in_minutes: 3
388
+ YAML
389
+ before(:each) { write_file(file, yaml) }
390
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
391
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
392
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
393
+ before(:each) { copy('%/sg.json', 'sg.json') }
394
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
395
+ before(:each) { copy('%/iam.json', 'iam.json') }
396
+ before(:each) { run_command('cfndk stack create --stack-names=Test Test2') }
397
+ it do
398
+ aggregate_failures do
399
+ expect(last_command_started).to be_successfully_executed
400
+ expect(last_command_started).to have_output(/INFO create.../)
401
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
402
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
403
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
404
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
405
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
406
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
407
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test3-#{uuid}$/)
408
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test3-#{uuid}$/)
409
+ expect(last_command_started).not_to have_output(/INFO created stack: Test3-#{uuid}$/)
410
+ end
411
+ end
412
+ after(:each) { run_command('cfndk destroy -f') }
413
+ end
414
+ end
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ describe 'destroy', destroy: true do
421
+ context 'when -f without cfndk.yml' do
422
+ before(:each) { run_command('cfndk stack destroy -f') }
423
+ it 'displays file does not exist error and status code = 1' do
424
+ aggregate_failures do
425
+ expect(last_command_started).to have_exit_status(1)
426
+ expect(last_command_started).to have_output(/ERROR File does not exist./)
427
+ end
428
+ end
429
+ end
430
+
431
+ context 'with cfndk2.yml' do
432
+ yaml = <<-"YAML"
433
+ stacks:
434
+ YAML
435
+ before(:each) { write_file(file2, yaml) }
436
+ context 'when -c cfndk2.yml -f and empty stacks' do
437
+ before(:each) { run_command("cfndk stack destroy -c=#{file2} -f") }
438
+ it 'displays empty stack log' do
439
+ aggregate_failures do
440
+ expect(last_command_started).to be_successfully_executed
441
+ expect(last_command_started).to have_output(/INFO destroy.../)
442
+ end
443
+ end
444
+ end
445
+
446
+ context 'when --config-path cfndk2.yml -f and empty stacks' do
447
+ before(:each) { run_command("cfndk stack destroy --config-path=#{file2} -f") }
448
+ it 'displays empty stack log' do
449
+ aggregate_failures do
450
+ expect(last_command_started).to be_successfully_executed
451
+ expect(last_command_started).to have_output(/INFO destroy.../)
452
+ end
453
+ end
454
+ end
455
+ end
456
+
457
+ context 'with cfndk.yml' do
458
+ context 'when cfndk.yml is empty' do
459
+ before(:each) { touch(file) }
460
+ before(:each) { run_command('cfndk stack destroy -f') }
461
+ it 'displays File is empty error and status code = 1' do
462
+ aggregate_failures do
463
+ expect(last_command_started).to have_exit_status(1)
464
+ expect(last_command_started).to have_output(/ERROR File is empty./)
465
+ end
466
+ end
467
+ end
468
+ context 'when enter no' do
469
+ yaml = <<-"YAML"
470
+ keypairs:
471
+ Test1:
472
+ stacks:
473
+ Test:
474
+ template_file: vpc.yaml
475
+ parameter_input: vpc.json
476
+ parameters:
477
+ VpcName: sample<%= append_uuid%>
478
+ timeout_in_minutes: 2
479
+ YAML
480
+ before(:each) { write_file(file, yaml) }
481
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
482
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
483
+ before(:each) { run_command('cfndk stack destroy') }
484
+ before(:each) { type('no') }
485
+ it 'displays confirm message and cancel message and status code = 2' do
486
+ aggregate_failures do
487
+ expect(last_command_started).to have_exit_status(2)
488
+ expect(last_command_started).to have_output(/INFO destroy../)
489
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
490
+ expect(last_command_started).to have_output(/INFO destroy command was canceled/)
491
+ expect(last_command_started).not_to have_output(/INFO deleting stack:/)
492
+ expect(last_command_started).not_to have_output(/INFO deleted stack:/)
493
+ expect(last_command_started).not_to have_output(/INFO do not delete keypair: Test1$/)
494
+ expect(last_command_started).not_to have_output(/INFO do not delete stack: Test$/)
495
+ end
496
+ end
497
+ end
498
+ context 'when enter yes' do
499
+ context 'when keyparis and stacks do not exist' do
500
+ yaml = <<-"YAML"
501
+ keypairs:
502
+ Test1:
503
+ stacks:
504
+ Test:
505
+ template_file: vpc.yaml
506
+ parameter_input: vpc.json
507
+ parameters:
508
+ VpcName: sample<%= append_uuid%>
509
+ timeout_in_minutes: 2
510
+ YAML
511
+ before(:each) { write_file(file, yaml) }
512
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
513
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
514
+ before(:each) { run_command('cfndk destroy -f') }
515
+ before(:each) { stop_all_commands }
516
+ before(:each) { run_command('cfndk stack destroy') }
517
+ before(:each) { type('yes') }
518
+ before(:each) { stop_all_commands }
519
+ it 'displays confirm message and do not delete message' do
520
+ aggregate_failures do
521
+ expect(last_command_started).to be_successfully_executed
522
+ expect(last_command_started).to have_output(/INFO destroy../)
523
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
524
+ expect(last_command_started).not_to have_output(/INFO do not delete keypair: Test1$/)
525
+ expect(last_command_started).to have_output(/INFO do not delete stack: Test$/)
526
+ end
527
+ end
528
+ end
529
+ context 'when keyparis and stacks exist' do
530
+ yaml = <<-"YAML"
531
+ keypairs:
532
+ Test1:
533
+ stacks:
534
+ Test:
535
+ template_file: vpc.yaml
536
+ parameter_input: vpc.json
537
+ parameters:
538
+ VpcName: sample<%= append_uuid%>
539
+ timeout_in_minutes: 2
540
+ YAML
541
+ before(:each) { write_file(file, yaml) }
542
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
543
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
544
+ before(:each) { run_command('cfndk create') }
545
+ before(:each) { stop_all_commands }
546
+ before(:each) { run_command('cfndk stack destroy') }
547
+ before(:each) { type('yes') }
548
+ before(:each) { stop_all_commands }
549
+ it 'displays confirm message and delete message' do
550
+ aggregate_failures do
551
+ expect(last_command_started).to be_successfully_executed
552
+ expect(last_command_started).to have_output(/INFO destroy../)
553
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
554
+ expect(last_command_started).not_to have_output(/INFO deleted keypair: Test1$/)
555
+ expect(last_command_started).to have_output(/INFO deleted stack: Test$/)
556
+ end
557
+ end
558
+ after(:each) { run_command('cfndk destroy -f') }
559
+ end
560
+ end
561
+ end
562
+ end
563
+
564
+ describe 'update', update: true do
565
+ context 'without cfndk.yml' do
566
+ before(:each) { run_command('cfndk stack update') }
567
+ it 'displays file does not exist error and status code = 1' do
568
+ aggregate_failures do
569
+ expect(last_command_started).to have_exit_status(1)
570
+ expect(last_command_started).to have_output(/ERROR File does not exist./)
571
+ end
572
+ end
573
+ end
574
+
575
+ context 'with cfndk2.yml' do
576
+ yaml = <<-"YAML"
577
+ keypairs:
578
+ YAML
579
+ before(:each) { write_file(file2, yaml) }
580
+ context 'when -c cfndk2.yml and empty stacks' do
581
+ before(:each) { run_command("cfndk stack update -c=#{file2}") }
582
+ it 'displays empty stack log' do
583
+ aggregate_failures do
584
+ expect(last_command_started).to be_successfully_executed
585
+ expect(last_command_started).to have_output(/INFO update.../)
586
+ end
587
+ end
588
+ end
589
+
590
+ context 'when --config-path cfndk2.yml and empty stacks' do
591
+ before(:each) { run_command("cfndk stack update --config-path=#{file2}") }
592
+ it 'displays empty stack log' do
593
+ aggregate_failures do
594
+ expect(last_command_started).to be_successfully_executed
595
+ expect(last_command_started).to have_output(/INFO update.../)
596
+ end
597
+ end
598
+ end
599
+ end
600
+
601
+ context 'with cfndk.yml' do
602
+ context 'when cfndk.yml is empty' do
603
+ before(:each) { touch(file) }
604
+ before(:each) { run_command('cfndk stack update') }
605
+ it 'displays File is empty error and status code = 1' do
606
+ aggregate_failures do
607
+ expect(last_command_started).to have_exit_status(1)
608
+ expect(last_command_started).to have_output(/ERROR File is empty./)
609
+ end
610
+ end
611
+ end
612
+ context 'when empty yaml' do
613
+ yaml = <<-"YAML"
614
+ stacks:
615
+ Test:
616
+ template_file: vpc.yaml
617
+ timeout_in_minutes: 2
618
+ YAML
619
+ before(:each) { write_file(file, yaml) }
620
+ before(:each) { copy('%/empty_resource.yaml', 'vpc.yaml') }
621
+ before(:each) { run_command('cfndk stack update') }
622
+ it 'Displays error message and status code = 1' do
623
+ aggregate_failures do
624
+ expect(last_command_started).to have_exit_status(1)
625
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
626
+ expect(last_command_started).to have_output(/ERROR Template format error: At least one Resources member must be defined\.$/)
627
+ end
628
+ end
629
+ end
630
+ context 'when invalid yaml' do
631
+ yaml = <<-"YAML"
632
+ stacks:
633
+ Test:
634
+ template_file: vpc.yaml
635
+ parameter_input: vpc.json
636
+ timeout_in_minutes: 2
637
+ YAML
638
+ before(:each) { write_file(file, yaml) }
639
+ before(:each) { copy('%/invalid_vpc.yaml', 'vpc.yaml') }
640
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
641
+ before(:each) { run_command('cfndk stack update') }
642
+ it 'Displays error message and status code = 1' do
643
+ aggregate_failures do
644
+ expect(last_command_started).to have_exit_status(1)
645
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
646
+ expect(last_command_started).to have_output(/ERROR \[\/Resources\] 'null' values are not allowed in templates$/)
647
+ end
648
+ end
649
+ end
650
+
651
+ context 'with stacks:' do
652
+ context 'without stack' do
653
+ before(:each) { write_file(file, 'stacks:') }
654
+ before(:each) { run_command('cfndk stack update') }
655
+ it do
656
+ aggregate_failures do
657
+ expect(last_command_started).to be_successfully_executed
658
+ expect(last_command_started).to have_output(/INFO update.../)
659
+ end
660
+ end
661
+ end
662
+
663
+ context 'with a stack', with_stack: true do
664
+ yaml = <<-"YAML"
665
+ stacks:
666
+ Test:
667
+ template_file: vpc.yaml
668
+ parameter_input: vpc.json
669
+ timeout_in_minutes: 2
670
+ YAML
671
+ before(:each) { write_file(file, yaml) }
672
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
673
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
674
+ context 'when stack already exist' do
675
+ context 'when same yaml' do
676
+ before(:each) { run_command_and_stop('cfndk stack create') }
677
+ before(:each) { run_command('cfndk stack update') }
678
+ it 'displays No update warn' do
679
+ aggregate_failures do
680
+ expect(last_command_started).to have_exit_status(0)
681
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
682
+ expect(last_command_started).to have_output(/INFO updating stack: Test$/)
683
+ expect(last_command_started).to have_output(/WARN No updates are to be performed\.: Test$/)
684
+ end
685
+ end
686
+ end
687
+ context 'when different yaml' do
688
+ before(:each) { run_command_and_stop('cfndk stack create') }
689
+ before(:each) { copy('%/vpc_different.yaml', 'vpc.yaml') }
690
+ before(:each) { run_command('cfndk stack update') }
691
+ it 'displays update log' do
692
+ aggregate_failures do
693
+ expect(last_command_started).to be_successfully_executed
694
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
695
+ expect(last_command_started).to have_output(/INFO updating stack: Test$/)
696
+ expect(last_command_started).to have_output(/INFO updated stack: Test$/)
697
+ end
698
+ end
699
+ end
700
+ end
701
+ context 'when stack does not exist' do
702
+ before(:each) { run_command('cfndk stack update') }
703
+ it 'displays no stack error and statu code = 1' do
704
+ aggregate_failures do
705
+ expect(last_command_started).to have_exit_status(1)
706
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
707
+ expect(last_command_started).to have_output(/INFO updating stack: Test$/)
708
+ expect(last_command_started).to have_output(/ERROR Stack \[Test\] does not exist$/)
709
+ end
710
+ end
711
+ end
712
+ after(:each) { run_command('cfndk destroy -f') }
713
+ end
714
+ context 'with two stacks' do
715
+ yaml = <<-"YAML"
716
+ stacks:
717
+ Test:
718
+ template_file: vpc.yaml
719
+ parameter_input: vpc.json
720
+ timeout_in_minutes: 4
721
+ Test2:
722
+ template_file: sg.yaml
723
+ parameter_input: sg.json
724
+ depends:
725
+ - Test
726
+ YAML
727
+ before(:each) { write_file(file, yaml) }
728
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
729
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
730
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
731
+ before(:each) { copy('%/sg.json', 'sg.json') }
732
+ before(:each) { run_command_and_stop('cfndk stack create') }
733
+ before(:each) { copy('%/sg_different.yaml', 'sg.yaml') }
734
+ before(:each) { run_command('cfndk stack update') }
735
+ it 'displays updated logs' do
736
+ aggregate_failures do
737
+ expect(last_command_started).to be_successfully_executed
738
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
739
+ expect(last_command_started).to have_output(/INFO updating stack: Test$/)
740
+ expect(last_command_started).to have_output(/WARN No updates are to be performed.: Test$/)
741
+ expect(last_command_started).to have_output(/INFO validate stack: Test2$/)
742
+ expect(last_command_started).to have_output(/INFO updating stack: Test2$/)
743
+ expect(last_command_started).to have_output(/INFO updated stack: Test2$/)
744
+ end
745
+ end
746
+ after(:each) { run_command('cfndk destroy -f') }
747
+ end
748
+ context 'when cyclic dependency', dependency: true do
749
+ yaml = <<-"YAML"
750
+ stacks:
751
+ Test:
752
+ template_file: vpc.yaml
753
+ parameter_input: vpc.json
754
+ timeout_in_minutes: 2
755
+ depends:
756
+ - Test2
757
+ Test2:
758
+ template_file: sg.yaml
759
+ parameter_input: sg.json
760
+ depends:
761
+ - Test
762
+ YAML
763
+
764
+ before(:each) { write_file(file, yaml) }
765
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
766
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
767
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
768
+ before(:each) { copy('%/sg.json', 'sg.json') }
769
+ before(:each) { run_command('cfndk stack update') }
770
+ it 'displays cyclic error log and exit status = 1' do
771
+ aggregate_failures do
772
+ expect(last_command_started).to have_exit_status(1)
773
+ expect(last_command_started).to have_output(/ERROR There are cyclic dependency or stack doesn't exist. unprocessed_stack: Test,Test2$/)
774
+ end
775
+ end
776
+ after(:each) { run_command('cfndk destroy -f') }
777
+ end
778
+ context 'when requires capabilities without capabilities', capabilities: true do
779
+ yaml = <<-"YAML"
780
+ stacks:
781
+ Test:
782
+ template_file: iam.yaml
783
+ parameter_input: iam.json
784
+ capabilities:
785
+ - CAPABILITY_NAMED_IAM
786
+ timeout_in_minutes: 3
787
+ YAML
788
+ yaml2 = <<-"YAML"
789
+ stacks:
790
+ Test:
791
+ template_file: iam.yaml
792
+ parameter_input: iam.json
793
+ timeout_in_minutes: 2
794
+ YAML
795
+ before(:each) { write_file(file, yaml) }
796
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
797
+ before(:each) { copy('%/iam.json', 'iam.json') }
798
+ before(:each) { run_command_and_stop('cfndk stack create') }
799
+ before(:each) { write_file(file, yaml2) }
800
+ before(:each) { run_command('cfndk stack update') }
801
+ it 'displays Requires capabilities log and exit status = 1' do
802
+ aggregate_failures do
803
+ expect(last_command_started).to have_exit_status(1)
804
+ expect(last_command_started).to have_output(/ERROR Requires capabilities : \[CAPABILITY_NAMED_IAM\]/)
805
+ end
806
+ end
807
+ after(:each) { run_command('cfndk destroy -f') }
808
+ end
809
+ context 'when success with capabilities', capabilities: true do
810
+ yaml = <<-"YAML"
811
+ stacks:
812
+ Test:
813
+ template_file: iam.yaml
814
+ parameter_input: iam.json
815
+ capabilities:
816
+ - CAPABILITY_NAMED_IAM
817
+ timeout_in_minutes: 3
818
+ YAML
819
+
820
+ before(:each) { write_file(file, yaml) }
821
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
822
+ before(:each) { copy('%/iam.json', 'iam.json') }
823
+ before(:each) { run_command_and_stop('cfndk stack create') }
824
+ before(:each) { copy('%/iam_different.json', 'iam.json') }
825
+ before(:each) { run_command('cfndk stack update') }
826
+ it 'displays updated log' do
827
+ aggregate_failures do
828
+ expect(last_command_started).to be_successfully_executed
829
+ expect(last_command_started).to have_output(/INFO updated stack: Test$/)
830
+ end
831
+ end
832
+ after(:each) { run_command('cfndk destroy -f') }
833
+ end
834
+ context 'with UUID', uuid: true do
835
+ context 'when -u 38437346-c75c-47c5-83b4-d504f85e275b' do
836
+ yaml = <<-"YAML"
837
+ stacks:
838
+ Test:
839
+ template_file: vpc.yaml
840
+ parameter_input: vpc.json
841
+ parameters:
842
+ VpcName: sample<%= append_uuid%>
843
+ timeout_in_minutes: 2
844
+ Test2:
845
+ template_file: sg.yaml
846
+ parameter_input: sg.json
847
+ parameters:
848
+ VpcName: sample<%= append_uuid%>
849
+ depends:
850
+ - Test
851
+ YAML
852
+ before(:each) { write_file(file, yaml) }
853
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
854
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
855
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
856
+ before(:each) { copy('%/sg.json', 'sg.json') }
857
+ before(:each) { run_command_and_stop("cfndk stack create -u=#{uuid}") }
858
+ before(:each) { copy('%/vpc_different.yaml', 'vpc.yaml') }
859
+ before(:each) { copy('%/sg_different.yaml', 'sg.yaml') }
860
+ before(:each) { run_command("cfndk stack update -u=#{uuid}") }
861
+ it 'displays updated logs' do
862
+ aggregate_failures do
863
+ expect(last_command_started).to be_successfully_executed
864
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
865
+ expect(last_command_started).to have_output(/INFO updating stack: Test-#{uuid}$/)
866
+ expect(last_command_started).to have_output(/INFO updated stack: Test-#{uuid}$/)
867
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
868
+ expect(last_command_started).to have_output(/INFO updating stack: Test2-#{uuid}$/)
869
+ expect(last_command_started).to have_output(/INFO updated stack: Test2-#{uuid}$/)
870
+ end
871
+ end
872
+ after(:each) { run_command("cfndk destroy -f -u=#{uuid}") }
873
+ end
874
+ context 'when env CFNDK_UUID=38437346-c75c-47c5-83b4-d504f85e275b' do
875
+ before(:each) { set_environment_variable('CFNDK_UUID', uuid) }
876
+ context 'with two stacks' do
877
+ yaml = <<-"YAML"
878
+ stacks:
879
+ Test:
880
+ template_file: vpc.yaml
881
+ parameter_input: vpc.json
882
+ parameters:
883
+ VpcName: sample<%= append_uuid%>
884
+ timeout_in_minutes: 2
885
+ Test2:
886
+ template_file: sg.yaml
887
+ parameter_input: sg.json
888
+ parameters:
889
+ VpcName: sample<%= append_uuid%>
890
+ depends:
891
+ - Test
892
+ YAML
893
+ before(:each) { write_file(file, yaml) }
894
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
895
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
896
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
897
+ before(:each) { copy('%/sg.json', 'sg.json') }
898
+ before(:each) { run_command_and_stop('cfndk stack create') }
899
+ before(:each) { copy('%/vpc_different.yaml', 'vpc.yaml') }
900
+ before(:each) { copy('%/sg_different.yaml', 'sg.yaml') }
901
+ before(:each) { run_command('cfndk stack update') }
902
+ it 'displays updated logs' do
903
+ aggregate_failures do
904
+ expect(last_command_started).to be_successfully_executed
905
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
906
+ expect(last_command_started).to have_output(/INFO updating stack: Test-#{uuid}$/)
907
+ expect(last_command_started).to have_output(/INFO updated stack: Test-#{uuid}$/)
908
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
909
+ expect(last_command_started).to have_output(/INFO updating stack: Test2-#{uuid}$/)
910
+ expect(last_command_started).to have_output(/INFO updated stack: Test2-#{uuid}$/)
911
+ end
912
+ end
913
+ after(:each) { run_command('cfndk destroy -f') }
914
+ end
915
+ context 'when --stack-names=Test' do
916
+ yaml = <<-"YAML"
917
+ stacks:
918
+ Test:
919
+ template_file: vpc.yaml
920
+ parameter_input: vpc.json
921
+ parameters:
922
+ VpcName: sample<%= append_uuid%>
923
+ timeout_in_minutes: 2
924
+ Test2:
925
+ template_file: sg.yaml
926
+ parameter_input: sg.json
927
+ parameters:
928
+ VpcName: sample<%= append_uuid%>
929
+ depends:
930
+ - Test
931
+ YAML
932
+ before(:each) { write_file(file, yaml) }
933
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
934
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
935
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
936
+ before(:each) { copy('%/sg.json', 'sg.json') }
937
+ before(:each) { run_command_and_stop('cfndk stack create') }
938
+ before(:each) { copy('%/vpc_different.yaml', 'vpc.yaml') }
939
+ before(:each) { run_command('cfndk stack update --stack-names=Test') }
940
+ it 'displays updated log of Test stack' do
941
+ aggregate_failures do
942
+ expect(last_command_started).to be_successfully_executed
943
+ expect(last_command_started).to have_output(/INFO update.../)
944
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
945
+ expect(last_command_started).to have_output(/INFO updating stack: Test-#{uuid}$/)
946
+ expect(last_command_started).to have_output(/INFO updated stack: Test-#{uuid}$/)
947
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test2-#{uuid}$/)
948
+ expect(last_command_started).not_to have_output(/INFO updating stack: Test2-#{uuid}$/)
949
+ expect(last_command_started).not_to have_output(/INFO updated stack: Test2-#{uuid}$/)
950
+ end
951
+ end
952
+ after(:each) { run_command('cfndk destroy -f') }
953
+ end
954
+ context 'when --stack-names=Test Test2' do
955
+ yaml = <<-"YAML"
956
+ stacks:
957
+ Test:
958
+ template_file: vpc.yaml
959
+ parameter_input: vpc.json
960
+ parameters:
961
+ VpcName: sample<%= append_uuid%>
962
+ timeout_in_minutes: 2
963
+ Test2:
964
+ template_file: sg.yaml
965
+ parameter_input: sg.json
966
+ parameters:
967
+ VpcName: sample<%= append_uuid%>
968
+ depends:
969
+ - Test
970
+ Test3:
971
+ template_file: iam.yaml
972
+ parameter_input: iam.json
973
+ parameters:
974
+ WebRoleName: WebhRole<%= append_uuid%>
975
+ capabilities:
976
+ - CAPABILITY_NAMED_IAM
977
+ timeout_in_minutes: 3
978
+ YAML
979
+ before(:each) { write_file(file, yaml) }
980
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
981
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
982
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
983
+ before(:each) { copy('%/sg.json', 'sg.json') }
984
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
985
+ before(:each) { copy('%/iam.json', 'iam.json') }
986
+ before(:each) { run_command_and_stop('cfndk stack create') }
987
+ before(:each) { copy('%/vpc_different.yaml', 'vpc.yaml') }
988
+ before(:each) { copy('%/sg_different.yaml', 'sg.yaml') }
989
+ before(:each) { run_command('cfndk stack update --stack-names=Test Test2') }
990
+ it 'displays updated logs of Test1/Test2 stacks' do
991
+ aggregate_failures do
992
+ expect(last_command_started).to be_successfully_executed
993
+ expect(last_command_started).to have_output(/INFO update.../)
994
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
995
+ expect(last_command_started).to have_output(/INFO updating stack: Test-#{uuid}$/)
996
+ expect(last_command_started).to have_output(/INFO updated stack: Test-#{uuid}$/)
997
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
998
+ expect(last_command_started).to have_output(/INFO updating stack: Test2-#{uuid}$/)
999
+ expect(last_command_started).to have_output(/INFO updated stack: Test2-#{uuid}$/)
1000
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test3-#{uuid}$/)
1001
+ expect(last_command_started).not_to have_output(/INFO updating stack: Test3-#{uuid}$/)
1002
+ expect(last_command_started).not_to have_output(/INFO updated stack: Test3-#{uuid}$/)
1003
+ end
1004
+ end
1005
+ after(:each) { run_command('cfndk destroy -f') }
1006
+ end
1007
+ end
1008
+ end
1009
+ end
1010
+ end
1011
+ end
1012
+
1013
+ describe 'validate', validate: true do
1014
+ context 'without cfndk.yml' do
1015
+ before(:each) { run_command('cfndk stack validate') }
1016
+ it 'displays file does not exist error and status code = 1' do
1017
+ aggregate_failures do
1018
+ expect(last_command_started).to have_exit_status(1)
1019
+ expect(last_command_started).to have_output(/ERROR File does not exist./)
1020
+ end
1021
+ end
1022
+ end
1023
+
1024
+ context 'with cfndk2.yml' do
1025
+ yaml = <<-"YAML"
1026
+ keypairs:
1027
+ YAML
1028
+ before(:each) { write_file(file2, yaml) }
1029
+ context 'when -c cfndk2.yml and empty stacks' do
1030
+ before(:each) { run_command("cfndk stack validate -c=#{file2}") }
1031
+ it 'displays empty stack log' do
1032
+ aggregate_failures do
1033
+ expect(last_command_started).to be_successfully_executed
1034
+ expect(last_command_started).to have_output(/INFO validate.../)
1035
+ end
1036
+ end
1037
+ end
1038
+ context 'when --config-path cfndk2.yml and empty stacks' do
1039
+ before(:each) { run_command("cfndk stack validate --config-path=#{file2}") }
1040
+ it 'displays empty stack log' do
1041
+ aggregate_failures do
1042
+ expect(last_command_started).to be_successfully_executed
1043
+ expect(last_command_started).to have_output(/INFO validate.../)
1044
+ end
1045
+ end
1046
+ end
1047
+ end
1048
+ context 'with cfndk.yml' do
1049
+ context 'when valid yaml' do
1050
+ yaml = <<-"YAML"
1051
+ stacks:
1052
+ Test:
1053
+ template_file: vpc.yaml
1054
+ parameter_input: vpc.json
1055
+ timeout_in_minutes: 2
1056
+ YAML
1057
+ before(:each) { write_file(file, yaml) }
1058
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
1059
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
1060
+ before(:each) { run_command('cfndk stack validate') }
1061
+ it 'Displays validate message' do
1062
+ aggregate_failures do
1063
+ expect(last_command_started).to have_exit_status(0)
1064
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
1065
+ end
1066
+ end
1067
+ end
1068
+ context 'when empty yaml' do
1069
+ yaml = <<-"YAML"
1070
+ stacks:
1071
+ Test:
1072
+ template_file: vpc.yaml
1073
+ timeout_in_minutes: 2
1074
+ YAML
1075
+ before(:each) { write_file(file, yaml) }
1076
+ before(:each) { copy('%/empty_resource.yaml', 'vpc.yaml') }
1077
+ before(:each) { run_command('cfndk stack validate') }
1078
+ it 'Displays error message and status code = 1' do
1079
+ aggregate_failures do
1080
+ expect(last_command_started).to have_exit_status(1)
1081
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
1082
+ expect(last_command_started).to have_output(/ERROR Template format error: At least one Resources member must be defined\.$/)
1083
+ end
1084
+ end
1085
+ end
1086
+ context 'when invalid yaml' do
1087
+ yaml = <<-"YAML"
1088
+ stacks:
1089
+ Test:
1090
+ template_file: vpc.yaml
1091
+ parameter_input: vpc.json
1092
+ timeout_in_minutes: 2
1093
+ YAML
1094
+ before(:each) { write_file(file, yaml) }
1095
+ before(:each) { copy('%/invalid_vpc.yaml', 'vpc.yaml') }
1096
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
1097
+ before(:each) { run_command('cfndk stack validate') }
1098
+ it 'Displays error message and status code = 1' do
1099
+ aggregate_failures do
1100
+ expect(last_command_started).to have_exit_status(1)
1101
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
1102
+ expect(last_command_started).to have_output(/ERROR \[\/Resources\] 'null' values are not allowed in templates$/)
1103
+ end
1104
+ end
1105
+ end
1106
+ end
1107
+ end
1108
+ describe 'report', report: true do
1109
+ context 'without cfndk.yml' do
1110
+ before(:each) { run_command('cfndk stack report') }
1111
+ it 'displays file does not exist error and status code = 1' do
1112
+ aggregate_failures do
1113
+ expect(last_command_started).to have_exit_status(1)
1114
+ expect(last_command_started).to have_output(/ERROR File does not exist./)
1115
+ end
1116
+ end
1117
+ end
1118
+
1119
+ context 'with cfndk2.yml' do
1120
+ yaml = <<-"YAML"
1121
+ keypairs:
1122
+ YAML
1123
+ before(:each) { write_file(file2, yaml) }
1124
+ context 'when -c cfndk2.yml and empty stacks' do
1125
+ before(:each) { run_command("cfndk stack report -c=#{file2}") }
1126
+ it 'displays empty stack log' do
1127
+ aggregate_failures do
1128
+ expect(last_command_started).to be_successfully_executed
1129
+ expect(last_command_started).to have_output(/INFO report.../)
1130
+ end
1131
+ end
1132
+ end
1133
+
1134
+ context 'when --config-path cfndk2.yml and empty stacks' do
1135
+ before(:each) { run_command("cfndk stack report --config-path=#{file2}") }
1136
+ it 'displays empty stack log' do
1137
+ aggregate_failures do
1138
+ expect(last_command_started).to be_successfully_executed
1139
+ expect(last_command_started).to have_output(/INFO report.../)
1140
+ end
1141
+ end
1142
+ end
1143
+ end
1144
+
1145
+ context 'with cfndk.yml' do
1146
+ context 'when cfndk.yml is empty' do
1147
+ before(:each) { touch('cfndk.yml') }
1148
+ before(:each) { run_command('cfndk stack report') }
1149
+ it 'displays File is empty error and status code = 1' do
1150
+ aggregate_failures do
1151
+ expect(last_command_started).to have_exit_status(1)
1152
+ expect(last_command_started).to have_output(/ERROR File is empty./)
1153
+ end
1154
+ end
1155
+ end
1156
+
1157
+ context 'with empty keypairs and stacks' do
1158
+ yaml = <<-"YAML"
1159
+ keypairs:
1160
+ stacks:
1161
+ YAML
1162
+ before(:each) { write_file('cfndk.yml', yaml) }
1163
+ before(:each) { run_command('cfndk stack report') }
1164
+ it 'displays empty stacks and keypairs report' do
1165
+ aggregate_failures do
1166
+ expect(last_command_started).to be_successfully_executed
1167
+ expect(last_command_started).to have_output(/INFO report.../)
1168
+ end
1169
+ end
1170
+ end
1171
+
1172
+ context 'with keypairs and stacks' do
1173
+ yaml = <<-"YAML"
1174
+ keypairs:
1175
+ Key1:
1176
+ Key2:
1177
+ stacks:
1178
+ Test:
1179
+ template_file: vpc.yaml
1180
+ parameter_input: vpc.json
1181
+ timeout_in_minutes: 2
1182
+ Test2:
1183
+ template_file: sg.yaml
1184
+ parameter_input: sg.json
1185
+ depends:
1186
+ - Test
1187
+ YAML
1188
+ context 'without UUID' do
1189
+ before(:each) { write_file('cfndk.yml', yaml) }
1190
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
1191
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
1192
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
1193
+ before(:each) { copy('%/sg.json', 'sg.json') }
1194
+ before(:each) { run_command_and_stop('cfndk create') }
1195
+ context 'without option' do
1196
+ before(:each) { run_command('cfndk stack report') }
1197
+ it 'displays stacks report' do
1198
+ aggregate_failures do
1199
+ expect(last_command_started).to be_successfully_executed
1200
+ expect(last_command_started).to have_output(/INFO stack: Test$/)
1201
+ expect(last_command_started).to have_output(/INFO stack: Test2$/)
1202
+ end
1203
+ end
1204
+ end
1205
+ context 'when --stack-names Test2' do
1206
+ before(:each) { run_command('cfndk stack report --stack-names Test2') }
1207
+ it 'displays stacks report' do
1208
+ aggregate_failures do
1209
+ expect(last_command_started).to be_successfully_executed
1210
+ expect(last_command_started).not_to have_output(/INFO stack: Test$/)
1211
+ expect(last_command_started).to have_output(/INFO stack: Test2$/)
1212
+ end
1213
+ end
1214
+ end
1215
+ context 'when --stack-names Test3' do
1216
+ before(:each) { run_command('cfndk stack report --stack-names Test3') }
1217
+ it 'displays stacks report' do
1218
+ aggregate_failures do
1219
+ expect(last_command_started).to be_successfully_executed
1220
+ expect(last_command_started).not_to have_output(/INFO stack: Test$/)
1221
+ expect(last_command_started).not_to have_output(/INFO stack: Test2$/)
1222
+ expect(last_command_started).not_to have_output(/INFO stack: Test3$/)
1223
+ end
1224
+ end
1225
+ end
1226
+ after(:each) { run_command('cfndk destroy -f') }
1227
+ end
1228
+ context 'with UUID' do
1229
+ before(:each) { write_file('cfndk.yml', yaml) }
1230
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
1231
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
1232
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
1233
+ before(:each) { copy('%/sg.json', 'sg.json') }
1234
+ before(:each) { run_command_and_stop('cfndk create -u 38437346-c75c-47c5-83b4-d504f85e275b') }
1235
+ context 'without option' do
1236
+ before(:each) { run_command('cfndk stack report -u 38437346-c75c-47c5-83b4-d504f85e275b') }
1237
+ it 'displays stacks report' do
1238
+ aggregate_failures do
1239
+ expect(last_command_started).to be_successfully_executed
1240
+ expect(last_command_started).to have_output(/INFO stack: Test-38437346-c75c-47c5-83b4-d504f85e275b$/)
1241
+ expect(last_command_started).to have_output(/INFO stack: Test2-38437346-c75c-47c5-83b4-d504f85e275b$/)
1242
+ end
1243
+ end
1244
+ end
1245
+ context 'when --stack-names Test2' do
1246
+ before(:each) { run_command('cfndk stack report -u 38437346-c75c-47c5-83b4-d504f85e275b --stack-names Test2') }
1247
+ it 'displays stacks report' do
1248
+ aggregate_failures do
1249
+ expect(last_command_started).to be_successfully_executed
1250
+ expect(last_command_started).not_to have_output(/INFO stack: Test-38437346-c75c-47c5-83b4-d504f85e275b$/)
1251
+ expect(last_command_started).to have_output(/INFO stack: Test2-38437346-c75c-47c5-83b4-d504f85e275b$/)
1252
+ end
1253
+ end
1254
+ end
1255
+ context 'when --stack-names Test3' do
1256
+ before(:each) { run_command('cfndk stack report -u 38437346-c75c-47c5-83b4-d504f85e275b --stack-names Test3') }
1257
+ it 'displays stacks report' do
1258
+ aggregate_failures do
1259
+ expect(last_command_started).to be_successfully_executed
1260
+ expect(last_command_started).not_to have_output(/INFO stack: Test-/)
1261
+ expect(last_command_started).not_to have_output(/INFO stack: Test2-/)
1262
+ expect(last_command_started).not_to have_output(/INFO stack: Test3-/)
1263
+ end
1264
+ end
1265
+ end
1266
+ after(:each) { run_command('cfndk destroy -f -u 38437346-c75c-47c5-83b4-d504f85e275b') }
1267
+ end
1268
+ end
1269
+ end
1270
+ end
1271
+ end
1272
+ end
1273
+ end