cfndk 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -14
  3. data/.gitignore +0 -1
  4. data/.rspec_parallel +6 -0
  5. data/Gemfile +1 -0
  6. data/Gemfile.lock +811 -0
  7. data/README.md +122 -10
  8. data/cfndk.gemspec +1 -0
  9. data/lib/cfndk/change_set_command.rb +97 -0
  10. data/lib/cfndk/command.rb +15 -181
  11. data/lib/cfndk/config_file_loadable.rb +13 -0
  12. data/lib/cfndk/global_config.rb +15 -0
  13. data/lib/cfndk/key_pair.rb +7 -4
  14. data/lib/cfndk/key_pair_command.rb +53 -0
  15. data/lib/cfndk/key_pairs.rb +2 -1
  16. data/lib/cfndk/logger.rb +1 -1
  17. data/lib/cfndk/stack.rb +382 -103
  18. data/lib/cfndk/stack_command.rb +110 -0
  19. data/lib/cfndk/stacks.rb +40 -14
  20. data/lib/cfndk/subcommand_help_returnable.rb +16 -0
  21. data/lib/cfndk/version.rb +1 -1
  22. data/lib/cfndk.rb +6 -0
  23. data/skel/cfndk.yml +4 -0
  24. data/spec/cfndk_change_set_create_spec.rb +436 -0
  25. data/spec/cfndk_change_set_destroy_spec.rb +160 -0
  26. data/spec/cfndk_change_set_execute_spec.rb +179 -0
  27. data/spec/cfndk_change_set_report_spec.rb +107 -0
  28. data/spec/cfndk_change_set_spec.rb +37 -0
  29. data/spec/cfndk_create_spec.rb +56 -141
  30. data/spec/cfndk_destroy_spec.rb +4 -2
  31. data/spec/cfndk_keypiar_spec.rb +11 -9
  32. data/spec/cfndk_report_spec.rb +3 -1
  33. data/spec/cfndk_spec.rb +5 -3
  34. data/spec/cfndk_stack_create_spec.rb +454 -0
  35. data/spec/cfndk_stack_destroy_spec.rb +161 -0
  36. data/spec/cfndk_stack_report_spec.rb +181 -0
  37. data/spec/cfndk_stack_spec.rb +6 -1146
  38. data/spec/cfndk_stack_update_spec.rb +467 -0
  39. data/spec/spec_helper.rb +4 -1
  40. data/spec/support/aruba.rb +1 -0
  41. metadata +42 -2
@@ -0,0 +1,454 @@
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
+ before(:each) { set_environment_variable('AWS_ACCESS_KEY_ID', ENV["AWS_ACCESS_KEY_ID#{ENV['TEST_ENV_NUMBER']}"]) }
7
+ before(:each) { set_environment_variable('AWS_SECRET_ACCESS_KEY', ENV["AWS_SECRET_ACCESS_KEY#{ENV['TEST_ENV_NUMBER']}"]) }
8
+ describe 'bin/cfndk' do
9
+ before(:each) { setup_aruba }
10
+ let(:file) { 'cfndk.yml' }
11
+ let(:file2) { 'cfndk2.yml' }
12
+ let(:pem) { 'test.pem' }
13
+ let(:uuid) { '38437346-c75c-47c5-83b4-d504f85e275b' }
14
+
15
+ describe 'stack' do
16
+ describe 'create', create: true do
17
+ context 'without cfndk.yml' do
18
+ before(:each) { run_command('cfndk stack create') }
19
+ it 'displays file does not exist error and status code = 1' do
20
+ aggregate_failures do
21
+ expect(last_command_started).to have_exit_status(1)
22
+ expect(last_command_started).to have_output(/ERROR RuntimeError: File does not exist./)
23
+ end
24
+ end
25
+ end
26
+
27
+ context 'with cfndk2.yml' do
28
+ yaml = <<-"YAML"
29
+ keypairs:
30
+ YAML
31
+ before(:each) { write_file(file2, yaml) }
32
+ context 'when -c cfndk2.yml and empty stacks' do
33
+ before(:each) { run_command("cfndk stack create -c=#{file2}") }
34
+ it 'displays empty stack log' do
35
+ aggregate_failures do
36
+ expect(last_command_started).to be_successfully_executed
37
+ expect(last_command_started).to have_output(/INFO create.../)
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'when --config-path cfndk2.yml and empty stacks' do
43
+ before(:each) { run_command("cfndk stack create --config-path=#{file2}") }
44
+ it 'displays empty stack log' do
45
+ aggregate_failures do
46
+ expect(last_command_started).to be_successfully_executed
47
+ expect(last_command_started).to have_output(/INFO create.../)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'with cfndk.yml' do
54
+ context 'when cfndk.yml is empty' do
55
+ before(:each) { touch(file) }
56
+ before(:each) { run_command('cfndk stack create') }
57
+ it 'displays File is empty error and status code = 1' do
58
+ aggregate_failures do
59
+ expect(last_command_started).to have_exit_status(1)
60
+ expect(last_command_started).to have_output(/ERROR File is empty./)
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'with stacks:' do
66
+ context 'without stack' do
67
+ before(:each) { write_file(file, 'stacks:') }
68
+ before(:each) { run_command('cfndk stack create') }
69
+ it do
70
+ aggregate_failures do
71
+ expect(last_command_started).to be_successfully_executed
72
+ expect(last_command_started).to have_output(/INFO create.../)
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'with a stack' do
78
+ yaml = <<-"YAML"
79
+ global:
80
+ stacks:
81
+ Test:
82
+ template_file: vpc.yaml
83
+ parameter_input: vpc.json
84
+ timeout_in_minutes: 2
85
+ YAML
86
+ before(:each) { write_file(file, yaml) }
87
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
88
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
89
+ before(:each) { run_command('cfndk stack create') }
90
+ it do
91
+ aggregate_failures do
92
+ expect(last_command_started).to be_successfully_executed
93
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
94
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
95
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
96
+ end
97
+ end
98
+ after(:each) { run_command('cfndk destroy -f') }
99
+ end
100
+ context 'with a 51200byte template stack' do
101
+ yaml = <<-"YAML"
102
+ global:
103
+ stacks:
104
+ Test:
105
+ template_file: vpc.yaml
106
+ parameter_input: vpc.json
107
+ timeout_in_minutes: 2
108
+ YAML
109
+ before(:each) { write_file(file, yaml) }
110
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
111
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
112
+ before(:each) { append_to_file('vpc.yaml', ' ' * (51200 - file_size('vpc.yaml').to_i)) }
113
+ before(:each) { run_command('cfndk stack create') }
114
+ it 'displays created stack log' do
115
+ aggregate_failures do
116
+ expect(last_command_started).to be_successfully_executed
117
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
118
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
119
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
120
+ expect(last_command_started).not_to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates})
121
+ end
122
+ end
123
+ after(:each) { run_command('cfndk destroy -f') }
124
+ end
125
+ context 'with a 51201byte template stack', big: true do
126
+ yaml = <<-"YAML"
127
+ global:
128
+ stacks:
129
+ Test:
130
+ template_file: vpc.yaml
131
+ parameter_input: vpc.json
132
+ timeout_in_minutes: 2
133
+ YAML
134
+ before(:each) { write_file(file, yaml) }
135
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
136
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
137
+ before(:each) { append_to_file('vpc.yaml', ' ' * (51200 + 1 - file_size('vpc.yaml').to_i)) }
138
+ before(:each) { run_command('cfndk stack create') }
139
+ it 'displays created stack log' do
140
+ aggregate_failures do
141
+ expect(last_command_started).to be_successfully_executed
142
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
143
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
144
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
145
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates})
146
+ end
147
+ end
148
+ after(:each) { run_command('cfndk destroy -f') }
149
+ end
150
+ context 'with two stacks' do
151
+ yaml = <<-"YAML"
152
+ stacks:
153
+ Test:
154
+ template_file: vpc.yaml
155
+ parameter_input: vpc.json
156
+ timeout_in_minutes: 2
157
+ Test2:
158
+ template_file: sg.yaml
159
+ parameter_input: sg.json
160
+ depends:
161
+ - Test
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 be_successfully_executed
173
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
174
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
175
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
176
+ expect(last_command_started).to have_output(/INFO validate stack: Test2$/)
177
+ expect(last_command_started).to have_output(/INFO creating stack: Test2$/)
178
+ expect(last_command_started).to have_output(/INFO created stack: Test2$/)
179
+ end
180
+ end
181
+ after(:each) { run_command('cfndk destroy -f') }
182
+ end
183
+ context 'when invalid dependency', dependency: true do
184
+ yaml = <<-"YAML"
185
+ stacks:
186
+ Test:
187
+ template_file: vpc.yaml
188
+ parameter_input: vpc.json
189
+ timeout_in_minutes: 2
190
+ depends:
191
+ - Test2
192
+ Test2:
193
+ template_file: sg.yaml
194
+ parameter_input: sg.json
195
+ YAML
196
+
197
+ before(:each) { write_file(file, yaml) }
198
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
199
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
200
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
201
+ before(:each) { copy('%/sg.json', 'sg.json') }
202
+ before(:each) { run_command('cfndk stack create') }
203
+ it do
204
+ aggregate_failures do
205
+ expect(last_command_started).to have_exit_status(1)
206
+ expect(last_command_started).to have_output(/ERROR Aws::Waiters::Errors::FailureStateError: stopped waiting, encountered a failure state$/)
207
+ end
208
+ end
209
+ after(:each) { run_command('cfndk destroy -f') }
210
+ end
211
+ context 'when cyclic dependency', dependency: true do
212
+ yaml = <<-"YAML"
213
+ stacks:
214
+ Test:
215
+ template_file: vpc.yaml
216
+ parameter_input: vpc.json
217
+ timeout_in_minutes: 2
218
+ depends:
219
+ - Test2
220
+ Test2:
221
+ template_file: sg.yaml
222
+ parameter_input: sg.json
223
+ depends:
224
+ - Test
225
+ YAML
226
+
227
+ before(:each) { write_file(file, yaml) }
228
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
229
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
230
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
231
+ before(:each) { copy('%/sg.json', 'sg.json') }
232
+ before(:each) { run_command('cfndk stack create') }
233
+ it do
234
+ aggregate_failures do
235
+ expect(last_command_started).to have_exit_status(1)
236
+ expect(last_command_started).to have_output(/ERROR RuntimeError: There are cyclic dependency or stack doesn't exist. unprocessed_stack: Test,Test2$/)
237
+ end
238
+ end
239
+ after(:each) { run_command('cfndk destroy -f') }
240
+ end
241
+ context 'when requires capabilities without capabilities', capabilities: true do
242
+ yaml = <<-"YAML"
243
+ stacks:
244
+ Test:
245
+ template_file: iam.yaml
246
+ parameter_input: iam.json
247
+ timeout_in_minutes: 2
248
+ YAML
249
+
250
+ before(:each) { write_file(file, yaml) }
251
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
252
+ before(:each) { copy('%/iam.json', 'iam.json') }
253
+ before(:each) { run_command('cfndk stack create') }
254
+ it do
255
+ aggregate_failures do
256
+ expect(last_command_started).to have_exit_status(1)
257
+ expect(last_command_started).to have_output(/ERROR Aws::CloudFormation::Errors::InsufficientCapabilitiesException: Requires capabilities : \[CAPABILITY_NAMED_IAM\]/)
258
+ end
259
+ end
260
+ after(:each) { run_command('cfndk destroy -f') }
261
+ end
262
+ context 'when success with capabilities', capabilities: true do
263
+ yaml = <<-"YAML"
264
+ stacks:
265
+ Test:
266
+ template_file: iam.yaml
267
+ parameter_input: iam.json
268
+ capabilities:
269
+ - CAPABILITY_NAMED_IAM
270
+ timeout_in_minutes: 3
271
+ YAML
272
+
273
+ before(:each) { write_file(file, yaml) }
274
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
275
+ before(:each) { copy('%/iam.json', 'iam.json') }
276
+ before(:each) { run_command('cfndk stack create') }
277
+ it do
278
+ aggregate_failures do
279
+ expect(last_command_started).to be_successfully_executed
280
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
281
+ end
282
+ end
283
+ after(:each) { run_command('cfndk destroy -f') }
284
+ end
285
+ context 'with UUID', uuid: true do
286
+ context 'when -u 38437346-c75c-47c5-83b4-d504f85e275b' do
287
+ yaml = <<-"YAML"
288
+ stacks:
289
+ Test:
290
+ template_file: vpc.yaml
291
+ parameter_input: vpc.json
292
+ parameters:
293
+ VpcName: sample<%= append_uuid%>
294
+ timeout_in_minutes: 2
295
+ Test2:
296
+ template_file: sg.yaml
297
+ parameter_input: sg.json
298
+ parameters:
299
+ VpcName: sample<%= append_uuid%>
300
+ depends:
301
+ - Test
302
+ YAML
303
+ before(:each) { write_file(file, yaml) }
304
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
305
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
306
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
307
+ before(:each) { copy('%/sg.json', 'sg.json') }
308
+ before(:each) { run_command("cfndk stack create -u=#{uuid}") }
309
+ it do
310
+ aggregate_failures do
311
+ expect(last_command_started).to be_successfully_executed
312
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
313
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
314
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
315
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
316
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
317
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
318
+ end
319
+ end
320
+ after(:each) { run_command("cfndk destroy -f -u=#{uuid}") }
321
+ end
322
+ context 'when env CFNDK_UUID=38437346-c75c-47c5-83b4-d504f85e275b' do
323
+ before(:each) { set_environment_variable('CFNDK_UUID', uuid) }
324
+ context 'with two stacks' do
325
+ yaml = <<-"YAML"
326
+ stacks:
327
+ Test:
328
+ template_file: vpc.yaml
329
+ parameter_input: vpc.json
330
+ parameters:
331
+ VpcName: sample<%= append_uuid%>
332
+ timeout_in_minutes: 2
333
+ Test2:
334
+ template_file: sg.yaml
335
+ parameter_input: sg.json
336
+ parameters:
337
+ VpcName: sample<%= append_uuid%>
338
+ depends:
339
+ - Test
340
+ YAML
341
+ before(:each) { write_file(file, yaml) }
342
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
343
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
344
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
345
+ before(:each) { copy('%/sg.json', 'sg.json') }
346
+ before(:each) { run_command('cfndk stack create') }
347
+ it do
348
+ aggregate_failures do
349
+ expect(last_command_started).to be_successfully_executed
350
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
351
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
352
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
353
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
354
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
355
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
356
+ end
357
+ end
358
+ after(:each) { run_command('cfndk destroy -f') }
359
+ end
360
+ context 'when --stack-names=Test' do
361
+ yaml = <<-"YAML"
362
+ stacks:
363
+ Test:
364
+ template_file: vpc.yaml
365
+ parameter_input: vpc.json
366
+ parameters:
367
+ VpcName: sample<%= append_uuid%>
368
+ timeout_in_minutes: 2
369
+ Test2:
370
+ template_file: sg.yaml
371
+ parameter_input: sg.json
372
+ parameters:
373
+ VpcName: sample<%= append_uuid%>
374
+ depends:
375
+ - Test
376
+ YAML
377
+ before(:each) { write_file(file, yaml) }
378
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
379
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
380
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
381
+ before(:each) { copy('%/sg.json', 'sg.json') }
382
+ before(:each) { run_command('cfndk stack create --stack-names=Test') }
383
+ it do
384
+ aggregate_failures do
385
+ expect(last_command_started).to be_successfully_executed
386
+ expect(last_command_started).to have_output(/INFO create.../)
387
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
388
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
389
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
390
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test2-#{uuid}$/)
391
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test2-#{uuid}$/)
392
+ expect(last_command_started).not_to have_output(/INFO created stack: Test2-#{uuid}$/)
393
+ end
394
+ end
395
+ after(:each) { run_command('cfndk destroy -f') }
396
+ end
397
+ context 'when --stack-names=Test Test2' do
398
+ yaml = <<-"YAML"
399
+ stacks:
400
+ Test:
401
+ template_file: vpc.yaml
402
+ parameter_input: vpc.json
403
+ parameters:
404
+ VpcName: sample<%= append_uuid%>
405
+ timeout_in_minutes: 2
406
+ Test2:
407
+ template_file: sg.yaml
408
+ parameter_input: sg.json
409
+ parameters:
410
+ VpcName: sample<%= append_uuid%>
411
+ depends:
412
+ - Test
413
+ Test3:
414
+ template_file: iam.yaml
415
+ parameter_input: iam.json
416
+ parameters:
417
+ WebRoleName: WebhRole<%= append_uuid%>
418
+ capabilities:
419
+ - CAPABILITY_NAMED_IAM
420
+ timeout_in_minutes: 3
421
+ YAML
422
+ before(:each) { write_file(file, yaml) }
423
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
424
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
425
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
426
+ before(:each) { copy('%/sg.json', 'sg.json') }
427
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
428
+ before(:each) { copy('%/iam.json', 'iam.json') }
429
+ before(:each) { run_command('cfndk stack create --stack-names=Test Test2') }
430
+ it do
431
+ aggregate_failures do
432
+ expect(last_command_started).to be_successfully_executed
433
+ expect(last_command_started).to have_output(/INFO create.../)
434
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
435
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
436
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
437
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
438
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
439
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
440
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test3-#{uuid}$/)
441
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test3-#{uuid}$/)
442
+ expect(last_command_started).not_to have_output(/INFO created stack: Test3-#{uuid}$/)
443
+ end
444
+ end
445
+ after(:each) { run_command('cfndk destroy -f') }
446
+ end
447
+ end
448
+ end
449
+ end
450
+ end
451
+ end
452
+ end
453
+ end
454
+ end
@@ -0,0 +1,161 @@
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
+ before(:each) { set_environment_variable('AWS_ACCESS_KEY_ID', ENV["AWS_ACCESS_KEY_ID#{ENV['TEST_ENV_NUMBER']}"]) }
7
+ before(:each) { set_environment_variable('AWS_SECRET_ACCESS_KEY', ENV["AWS_SECRET_ACCESS_KEY#{ENV['TEST_ENV_NUMBER']}"]) }
8
+ describe 'bin/cfndk' do
9
+ before(:each) { setup_aruba }
10
+ let(:file) { 'cfndk.yml' }
11
+ let(:file2) { 'cfndk2.yml' }
12
+ let(:pem) { 'test.pem' }
13
+ let(:uuid) { '38437346-c75c-47c5-83b4-d504f85e275b' }
14
+
15
+ describe 'stack' do
16
+ describe 'destroy', destroy: true do
17
+ context 'when -f without cfndk.yml' do
18
+ before(:each) { run_command('cfndk stack destroy -f') }
19
+ it 'displays file does not exist error and status code = 1' do
20
+ aggregate_failures do
21
+ expect(last_command_started).to have_exit_status(1)
22
+ expect(last_command_started).to have_output(/ERROR RuntimeError: File does not exist./)
23
+ end
24
+ end
25
+ end
26
+
27
+ context 'with cfndk2.yml' do
28
+ yaml = <<-"YAML"
29
+ stacks:
30
+ YAML
31
+ before(:each) { write_file(file2, yaml) }
32
+ context 'when -c cfndk2.yml -f and empty stacks' do
33
+ before(:each) { run_command("cfndk stack destroy -c=#{file2} -f") }
34
+ it 'displays empty stack log' do
35
+ aggregate_failures do
36
+ expect(last_command_started).to be_successfully_executed
37
+ expect(last_command_started).to have_output(/INFO destroy.../)
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'when --config-path cfndk2.yml -f and empty stacks' do
43
+ before(:each) { run_command("cfndk stack destroy --config-path=#{file2} -f") }
44
+ it 'displays empty stack log' do
45
+ aggregate_failures do
46
+ expect(last_command_started).to be_successfully_executed
47
+ expect(last_command_started).to have_output(/INFO destroy.../)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'with cfndk.yml' do
54
+ context 'when cfndk.yml is empty' do
55
+ before(:each) { touch(file) }
56
+ before(:each) { run_command('cfndk stack destroy -f') }
57
+ it 'displays File is empty error and status code = 1' do
58
+ aggregate_failures do
59
+ expect(last_command_started).to have_exit_status(1)
60
+ expect(last_command_started).to have_output(/ERROR File is empty./)
61
+ end
62
+ end
63
+ end
64
+ context 'when enter no' do
65
+ yaml = <<-"YAML"
66
+ keypairs:
67
+ Test1:
68
+ stacks:
69
+ Test:
70
+ template_file: vpc.yaml
71
+ parameter_input: vpc.json
72
+ parameters:
73
+ VpcName: sample<%= append_uuid%>
74
+ timeout_in_minutes: 2
75
+ YAML
76
+ before(:each) { write_file(file, yaml) }
77
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
78
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
79
+ before(:each) { run_command('cfndk stack destroy') }
80
+ before(:each) { type('no') }
81
+ it 'displays confirm message and cancel message and status code = 2' do
82
+ aggregate_failures do
83
+ expect(last_command_started).to have_exit_status(2)
84
+ expect(last_command_started).to have_output(/INFO destroy../)
85
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
86
+ expect(last_command_started).to have_output(/INFO destroy command was canceled/)
87
+ expect(last_command_started).not_to have_output(/INFO deleting stack:/)
88
+ expect(last_command_started).not_to have_output(/INFO deleted stack:/)
89
+ expect(last_command_started).not_to have_output(/INFO do not delete keypair: Test1$/)
90
+ expect(last_command_started).not_to have_output(/INFO do not delete stack: Test$/)
91
+ end
92
+ end
93
+ end
94
+ context 'when enter yes' do
95
+ context 'when keyparis and stacks do not exist' do
96
+ yaml = <<-"YAML"
97
+ keypairs:
98
+ Test1:
99
+ stacks:
100
+ Test:
101
+ template_file: vpc.yaml
102
+ parameter_input: vpc.json
103
+ parameters:
104
+ VpcName: sample<%= append_uuid%>
105
+ timeout_in_minutes: 2
106
+ YAML
107
+ before(:each) { write_file(file, yaml) }
108
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
109
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
110
+ before(:each) { run_command('cfndk destroy -f') }
111
+ before(:each) { stop_all_commands }
112
+ before(:each) { run_command('cfndk stack destroy') }
113
+ before(:each) { type('yes') }
114
+ before(:each) { stop_all_commands }
115
+ it 'displays confirm message and do not delete message' do
116
+ aggregate_failures do
117
+ expect(last_command_started).to be_successfully_executed
118
+ expect(last_command_started).to have_output(/INFO destroy../)
119
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
120
+ expect(last_command_started).not_to have_output(/INFO do not delete keypair: Test1$/)
121
+ expect(last_command_started).to have_output(/INFO do not delete stack: Test$/)
122
+ end
123
+ end
124
+ end
125
+ context 'when keyparis and stacks exist' do
126
+ yaml = <<-"YAML"
127
+ keypairs:
128
+ Test1:
129
+ stacks:
130
+ Test:
131
+ template_file: vpc.yaml
132
+ parameter_input: vpc.json
133
+ parameters:
134
+ VpcName: sample<%= append_uuid%>
135
+ timeout_in_minutes: 2
136
+ YAML
137
+ before(:each) { write_file(file, yaml) }
138
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
139
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
140
+ before(:each) { run_command('cfndk create') }
141
+ before(:each) { stop_all_commands }
142
+ before(:each) { run_command('cfndk stack destroy') }
143
+ before(:each) { type('yes') }
144
+ before(:each) { stop_all_commands }
145
+ it 'displays confirm message and delete message' do
146
+ aggregate_failures do
147
+ expect(last_command_started).to be_successfully_executed
148
+ expect(last_command_started).to have_output(/INFO destroy../)
149
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
150
+ expect(last_command_started).not_to have_output(/INFO deleted keypair: Test1$/)
151
+ expect(last_command_started).to have_output(/INFO deleted stack: Test$/)
152
+ end
153
+ end
154
+ after(:each) { run_command('cfndk destroy -f') }
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end