cfndk 0.0.7 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +79 -0
  3. data/.gitignore +1 -1
  4. data/.rspec +2 -0
  5. data/.rspec_parallel +6 -0
  6. data/.simplecov +9 -0
  7. data/Gemfile +11 -1
  8. data/Gemfile.lock +815 -0
  9. data/README.md +269 -76
  10. data/bin/cfndk +3 -18
  11. data/cfndk.gemspec +15 -6
  12. data/docker/Dockerfile +8 -0
  13. data/docker/build.sh +3 -0
  14. data/docker/cfndk.sh +14 -0
  15. data/lib/cfndk.rb +36 -0
  16. data/lib/cfndk/change_set_command.rb +103 -0
  17. data/lib/cfndk/command.rb +125 -119
  18. data/lib/cfndk/config_file_loadable.rb +13 -0
  19. data/lib/cfndk/credential_provider_chain.rb +12 -42
  20. data/lib/cfndk/credential_resolvable.rb +10 -0
  21. data/lib/cfndk/diff.rb +38 -0
  22. data/lib/cfndk/global_config.rb +46 -0
  23. data/lib/cfndk/key_pair.rb +66 -14
  24. data/lib/cfndk/key_pair_command.rb +60 -0
  25. data/lib/cfndk/key_pairs.rb +22 -5
  26. data/lib/cfndk/logger.rb +12 -3
  27. data/lib/cfndk/stack.rb +427 -126
  28. data/lib/cfndk/stack_command.rb +128 -0
  29. data/lib/cfndk/stacks.rb +48 -22
  30. data/lib/cfndk/subcommand_help_returnable.rb +16 -0
  31. data/lib/cfndk/template_packager.rb +210 -0
  32. data/lib/cfndk/uuid.rb +10 -0
  33. data/lib/cfndk/version.rb +1 -1
  34. data/skel/cfndk.yml +4 -0
  35. data/spec/.gitignore +1 -0
  36. data/spec/cfndk_change_set_create_spec.rb +436 -0
  37. data/spec/cfndk_change_set_destroy_spec.rb +160 -0
  38. data/spec/cfndk_change_set_execute_spec.rb +179 -0
  39. data/spec/cfndk_change_set_report_spec.rb +107 -0
  40. data/spec/cfndk_change_set_spec.rb +37 -0
  41. data/spec/cfndk_create_spec.rb +504 -0
  42. data/spec/cfndk_destroy_spec.rb +148 -0
  43. data/spec/cfndk_keypiar_spec.rb +397 -0
  44. data/spec/cfndk_report_spec.rb +164 -0
  45. data/spec/cfndk_spec.rb +103 -0
  46. data/spec/cfndk_stack_create_spec.rb +814 -0
  47. data/spec/cfndk_stack_destroy_spec.rb +225 -0
  48. data/spec/cfndk_stack_report_spec.rb +181 -0
  49. data/spec/cfndk_stack_spec.rb +133 -0
  50. data/spec/cfndk_stack_update_spec.rb +553 -0
  51. data/spec/fixtures/big_vpc.yaml +533 -0
  52. data/spec/fixtures/empty_resource.yaml +2 -0
  53. data/spec/fixtures/iam.json +8 -0
  54. data/spec/fixtures/iam.yaml +38 -0
  55. data/spec/fixtures/iam_different.json +8 -0
  56. data/spec/fixtures/invalid_vpc.yaml +21 -0
  57. data/spec/fixtures/lambda_function/index.js +4 -0
  58. data/spec/fixtures/lambda_function/lambda_function.json +4 -0
  59. data/spec/fixtures/lambda_function/lambda_function.yaml +28 -0
  60. data/spec/fixtures/nested_stack.json +35 -0
  61. data/spec/fixtures/nested_stack.yaml +20 -0
  62. data/spec/fixtures/serverless_function/index.js +4 -0
  63. data/spec/fixtures/serverless_function/serverless_function.json +4 -0
  64. data/spec/fixtures/serverless_function/serverless_function.yaml +21 -0
  65. data/spec/fixtures/sg.json +8 -0
  66. data/spec/fixtures/sg.yaml +27 -0
  67. data/spec/fixtures/sg_different.yaml +22 -0
  68. data/spec/fixtures/stack.json +8 -0
  69. data/spec/fixtures/stack.template.json +39 -0
  70. data/spec/fixtures/stack.yaml +22 -0
  71. data/spec/fixtures/vpc.json +8 -0
  72. data/spec/fixtures/vpc.template.json +40 -0
  73. data/spec/fixtures/vpc.yaml +21 -0
  74. data/spec/fixtures/vpc_different.yaml +21 -0
  75. data/spec/spec_helper.rb +14 -0
  76. data/spec/support/aruba.rb +6 -0
  77. data/vagrant/Vagrantfile +89 -0
  78. metadata +259 -31
@@ -0,0 +1,148 @@
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 'destroy', destroy: true do
16
+ context 'without cfndk.yml' do
17
+ before(:each) { run_command('cfndk destroy -f') }
18
+ it 'displays file does not exist error and status code = 1' do
19
+ aggregate_failures do
20
+ expect(last_command_started).to have_exit_status(1)
21
+ expect(last_command_started).to have_output(/ERROR RuntimeError: File does not exist./)
22
+ end
23
+ end
24
+ end
25
+ context 'with cfndk2.yml' do
26
+ context 'when -c cfndk2.yml and empty stacks' do
27
+ yaml = <<-"YAML"
28
+ stacks:
29
+ YAML
30
+ before(:each) { write_file(file2, yaml) }
31
+ before(:each) { run_command("cfndk destroy -f -c=#{file2}") }
32
+ it do
33
+ aggregate_failures do
34
+ expect(last_command_started).to be_successfully_executed
35
+ expect(last_command_started).to have_output(/INFO destroy.../)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ context 'with cfndk.yml' do
41
+ context 'when cfndk.yml is empty' do
42
+ before(:each) { touch(file) }
43
+ before(:each) { run_command('cfndk destroy -f') }
44
+ it 'displays File is empty error and status code = 1' do
45
+ aggregate_failures do
46
+ expect(last_command_started).to have_exit_status(1)
47
+ expect(last_command_started).to have_output(/ERROR File is empty./)
48
+ end
49
+ end
50
+ end
51
+ context 'when enter no' do
52
+ yaml = <<-"YAML"
53
+ keypairs:
54
+ Test1:
55
+ stacks:
56
+ Test:
57
+ template_file: vpc.yaml
58
+ parameter_input: vpc.json
59
+ parameters:
60
+ VpcName: sample<%= append_uuid%>
61
+ timeout_in_minutes: 2
62
+ YAML
63
+ before(:each) { write_file(file, yaml) }
64
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
65
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
66
+ before(:each) { run_command('cfndk destroy') }
67
+ before(:each) { type('no') }
68
+ it 'displays confirm message and cancel message and status code = 2' do
69
+ aggregate_failures do
70
+ expect(last_command_started).to have_exit_status(2)
71
+ expect(last_command_started).to have_output(/INFO destroy../)
72
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
73
+ expect(last_command_started).to have_output(/INFO destroy command was canceled/)
74
+ expect(last_command_started).not_to have_output(/INFO deleting stack:/)
75
+ expect(last_command_started).not_to have_output(/INFO deleted stack:/)
76
+ expect(last_command_started).not_to have_output(/INFO do not delete keypair: Test1$/)
77
+ expect(last_command_started).not_to have_output(/INFO do not delete stack: Test$/)
78
+ end
79
+ end
80
+ end
81
+ context 'when enter yes' do
82
+ context 'when keyparis and stacks do not exist' do
83
+ yaml = <<-"YAML"
84
+ keypairs:
85
+ Test1:
86
+ stacks:
87
+ Test:
88
+ template_file: vpc.yaml
89
+ parameter_input: vpc.json
90
+ parameters:
91
+ VpcName: sample<%= append_uuid%>
92
+ timeout_in_minutes: 2
93
+ YAML
94
+ before(:each) { write_file(file, yaml) }
95
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
96
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
97
+ before(:each) { run_command('cfndk destroy -f') }
98
+ before(:each) { stop_all_commands }
99
+ before(:each) { run_command('cfndk destroy') }
100
+ before(:each) { type('yes') }
101
+ before(:each) { stop_all_commands }
102
+ it 'displays confirm message and do not delete message' do
103
+ aggregate_failures do
104
+ expect(last_command_started).to be_successfully_executed
105
+ expect(last_command_started).to have_output(/INFO destroy../)
106
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
107
+ expect(last_command_started).to have_output(/INFO do not delete keypair: Test1$/)
108
+ expect(last_command_started).to have_output(/INFO do not delete stack: Test$/)
109
+ end
110
+ end
111
+ end
112
+ context 'when keyparis and stacks exist', aaa: true do
113
+ yaml = <<-"YAML"
114
+ keypairs:
115
+ Test1:
116
+ stacks:
117
+ Test:
118
+ template_file: vpc.yaml
119
+ parameter_input: vpc.json
120
+ parameters:
121
+ VpcName: sample<%= append_uuid%>
122
+ timeout_in_minutes: 2
123
+ YAML
124
+ before(:each) { write_file(file, yaml) }
125
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
126
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
127
+ before(:each) { run_command('cfndk create') }
128
+ before(:each) { stop_all_commands }
129
+ before(:each) { run_command('cfndk destroy') }
130
+ before(:each) { type('yes') }
131
+ before(:each) { stop_all_commands }
132
+ it 'displays confirm message and delete message and stack was deleted' do
133
+ aggregate_failures do
134
+ expect(last_command_started).to be_successfully_executed
135
+ expect(last_command_started).to have_output(/INFO destroy../)
136
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
137
+ expect(last_command_started).to have_output(/INFO deleted keypair: Test1$/)
138
+ expect(last_command_started).to have_output(/INFO deleted stack: Test$/)
139
+ expect { cloudformation_stack('Test').exist }.to raise_error(Aws::CloudFormation::Errors::ValidationError)
140
+ end
141
+ end
142
+ after(:each) { run_command('cfndk destroy -f') }
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,397 @@
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 'keypair' do
16
+ context 'without subcommand', help: true do
17
+ before(:each) { run_command('cfndk keypair') }
18
+ it 'displays help and status code = 2' do
19
+ aggregate_failures do
20
+ expect(last_command_started).to have_exit_status(2)
21
+ end
22
+ end
23
+ end
24
+
25
+ describe 'help', help: true do
26
+ context 'without subsubcommand' do
27
+ before(:each) { run_command('cfndk keypair help') }
28
+ it 'displays help and status code = 2' do
29
+ aggregate_failures do
30
+ expect(last_command_started).to have_exit_status(2)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ describe 'create' do
37
+ context 'without cfndk.yml' do
38
+ before(:each) { run_command('cfndk keypair create') }
39
+ it 'displays file does not exist 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 RuntimeError: File does not exist./)
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'with cfndk2.yml' do
48
+ yaml = <<-"YAML"
49
+ keypairs:
50
+ YAML
51
+ before(:each) { write_file(file2, yaml) }
52
+ context 'when -c cfndk2.yml and empty keypairs' do
53
+ before(:each) { run_command("cfndk keypair create -c=#{file2}") }
54
+ it 'displays empty keypair log' do
55
+ aggregate_failures do
56
+ expect(last_command_started).to be_successfully_executed
57
+ expect(last_command_started).to have_output(/INFO create.../)
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'when --config-path cfndk2.yml and empty keypairs' do
63
+ before(:each) { run_command("cfndk keypair create --config-path=#{file2}") }
64
+ it 'displays empty keypair log' do
65
+ aggregate_failures do
66
+ expect(last_command_started).to be_successfully_executed
67
+ expect(last_command_started).to have_output(/INFO create.../)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ context 'with cfndk.yml' do
73
+ context 'when cfndk.yml is empty' do
74
+ before(:each) { touch(file) }
75
+ before(:each) { run_command('cfndk keypair create') }
76
+ it 'displays File is empty error and status code = 1' do
77
+ aggregate_failures do
78
+ expect(last_command_started).to have_exit_status(1)
79
+ expect(last_command_started).to have_output(/ERROR File is empty./)
80
+ end
81
+ end
82
+ end
83
+
84
+ context 'with keyparis:', keypairs: true do
85
+ context 'without keypair' do
86
+ before(:each) { write_file(file, 'keypairs:') }
87
+ before(:each) { run_command('cfndk keypair create') }
88
+ it do
89
+ aggregate_failures do
90
+ expect(last_command_started).to be_successfully_executed
91
+ expect(last_command_started).to have_output(/INFO create.../)
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'with stacks:' do
97
+ before(:each) { write_file(file, 'stacks:') }
98
+ before(:each) { run_command('cfndk keypair create') }
99
+ it do
100
+ aggregate_failures do
101
+ expect(last_command_started).to be_successfully_executed
102
+ expect(last_command_started).to have_output(/INFO create.../)
103
+ end
104
+ end
105
+ end
106
+
107
+ context 'with a keypair' do
108
+ yaml = <<-"YAML"
109
+ keypairs:
110
+ Test:
111
+ YAML
112
+ before(:each) { write_file(file, yaml) }
113
+ before(:each) { run_command('cfndk keypair create') }
114
+ it do
115
+ aggregate_failures do
116
+ expect(last_command_started).to be_successfully_executed
117
+ expect(last_command_started).to have_output(/INFO creating keypair: Test/)
118
+ expect(last_command_started).to have_output(/INFO created keypair: Test/)
119
+ end
120
+ end
121
+ after(:each) { run_command('cfndk destroy -f') }
122
+ end
123
+
124
+ context 'with two keypairs' do
125
+ yaml = <<-"YAML"
126
+ keypairs:
127
+ Foo:
128
+ Bar:
129
+ YAML
130
+ before(:each) { write_file(file, yaml) }
131
+ before(:each) { run_command('cfndk keypair create') }
132
+ it do
133
+ aggregate_failures do
134
+ expect(last_command_started).to be_successfully_executed
135
+ expect(last_command_started).to have_output(/INFO creating keypair: Foo/)
136
+ expect(last_command_started).to have_output(/INFO created keypair: Foo/)
137
+ expect(last_command_started).to have_output(/INFO creating keypair: Bar/)
138
+ expect(last_command_started).to have_output(/INFO created keypair: Bar/)
139
+ end
140
+ end
141
+ after(:each) { run_command('cfndk destroy -f') }
142
+ end
143
+
144
+ context 'with a keypair and a key_file' do
145
+ context 'without UUID', uuid: true do
146
+ context 'without append_uuid' do
147
+ yaml = <<-"YAML"
148
+ keypairs:
149
+ Test:
150
+ key_file: test.pem
151
+ YAML
152
+ before(:each) { write_file(file, yaml) }
153
+ before(:each) { run_command('cfndk keypair create') }
154
+ it do
155
+ aggregate_failures do
156
+ expect(last_command_started).to be_successfully_executed
157
+ expect(last_command_started).to have_output(/INFO create.../)
158
+ expect(last_command_started).to have_output(/INFO creating keypair: Test$/)
159
+ expect(last_command_started).to have_output(/INFO created keypair: Test$/)
160
+ expect(last_command_started).to have_output(/create key file: #{pem}$/)
161
+ expect(pem).to be_an_existing_file
162
+ expect(pem).to have_file_content(/-----END RSA PRIVATE KEY-----/)
163
+ end
164
+ end
165
+ after(:each) { run_command('cfndk destroy -f') }
166
+ end
167
+
168
+ context 'with append_uuid' do
169
+ yaml = <<-"YAML"
170
+ keypairs:
171
+ Test:
172
+ key_file: test<%= append_uuid %>.pem
173
+ YAML
174
+ before(:each) { write_file(file, yaml) }
175
+ before(:each) { run_command('cfndk keypair create') }
176
+ it do
177
+ aggregate_failures do
178
+ expect(last_command_started).to be_successfully_executed
179
+ expect(last_command_started).to have_output(/INFO create.../)
180
+ expect(last_command_started).to have_output(/INFO creating keypair: Test$/)
181
+ expect(last_command_started).to have_output(/INFO created keypair: Test$/)
182
+ expect(last_command_started).to have_output(/create key file: #{pem}/)
183
+ expect(pem).to be_an_existing_file
184
+ expect(pem).to have_file_content(/-----END RSA PRIVATE KEY-----/)
185
+ end
186
+ end
187
+ after(:each) { run_command('cfndk destroy -f') }
188
+ end
189
+ end
190
+
191
+ context 'with UUID', uuid: true do
192
+ yaml = <<-"YAML"
193
+ keypairs:
194
+ Test:
195
+ key_file: test<%= append_uuid %>.pem
196
+ YAML
197
+ before(:each) { write_file(file, yaml) }
198
+ context 'when -u 38437346-c75c-47c5-83b4-d504f85e275b' do
199
+ before(:each) { run_command("cfndk keypair create -u=#{uuid}") }
200
+ it do
201
+ aggregate_failures do
202
+ expect(last_command_started).to be_successfully_executed
203
+ expect(last_command_started).to have_output(/INFO create.../)
204
+ expect(last_command_started).to have_output(/INFO creating keypair: Test-#{uuid}/)
205
+ expect(last_command_started).to have_output(/INFO created keypair: Test-#{uuid}/)
206
+ expect(last_command_started).to have_output(/create key file: test-#{uuid}.pem/)
207
+ expect("test-#{uuid}.pem").to be_an_existing_file
208
+ expect("test-#{uuid}.pem").to have_file_content(/-----END RSA PRIVATE KEY-----/)
209
+ end
210
+ end
211
+ after(:each) { run_command("cfndk destroy -u=#{uuid} -f") }
212
+ end
213
+
214
+ context 'when env CFNDK_UUID=38437346-c75c-47c5-83b4-d504f85e275b' do
215
+ before(:each) { set_environment_variable('CFNDK_UUID', uuid) }
216
+ before(:each) { run_command('cfndk keypair create') }
217
+ it 'runs the command with the expected results' do
218
+ aggregate_failures do
219
+ expect(last_command_started).to be_successfully_executed
220
+ expect(last_command_started).to have_output(/INFO create.../)
221
+ expect(last_command_started).to have_output(/INFO creating keypair: Test-#{uuid}/)
222
+ expect(last_command_started).to have_output(/INFO created keypair: Test-#{uuid}/)
223
+ expect(last_command_started).to have_output(/create key file: test-#{uuid}.pem/)
224
+ expect("test-#{uuid}.pem").to be_an_existing_file
225
+ expect("test-#{uuid}.pem").to have_file_content(/-----END RSA PRIVATE KEY-----/)
226
+ end
227
+ end
228
+ after(:each) { run_command('cfndk destroy -f') }
229
+ end
230
+ end
231
+ end
232
+ context 'with keypairs' do
233
+ yaml = <<-"YAML"
234
+ keypairs:
235
+ Test1:
236
+ Test2:
237
+ Test3:
238
+ YAML
239
+ before(:each) { write_file(file, yaml) }
240
+ context 'when --keypair-names=Test1 Test3' do
241
+ context 'without UUID' do
242
+ before(:each) { run_command('cfndk keypair create --keypair-names=Test1 Test3') }
243
+ it do
244
+ aggregate_failures do
245
+ expect(last_command_started).to be_successfully_executed
246
+ expect(last_command_started).to have_output(/INFO create.../)
247
+ expect(last_command_started).to have_output(/INFO creating keypair: Test1/)
248
+ expect(last_command_started).to have_output(/INFO created keypair: Test1/)
249
+ expect(last_command_started).not_to have_output(/INFO creating keypair: Test2/)
250
+ expect(last_command_started).not_to have_output(/INFO created keypair: Test2/)
251
+ expect(last_command_started).to have_output(/INFO creating keypair: Test3/)
252
+ expect(last_command_started).to have_output(/INFO created keypair: Test3/)
253
+ end
254
+ end
255
+ after(:each) { run_command('cfndk destroy -f') }
256
+ end
257
+ context 'with UUID' do
258
+ context 'when env CFNDK_UUID=38437346-c75c-47c5-83b4-d504f85e275b' do
259
+ before(:each) { set_environment_variable('CFNDK_UUID', uuid) }
260
+ before(:each) { run_command('cfndk keypair create --keypair-names=Test1 Test3') }
261
+ it do
262
+ aggregate_failures do
263
+ expect(last_command_started).to be_successfully_executed
264
+ expect(last_command_started).to have_output(/INFO create.../)
265
+ expect(last_command_started).to have_output(/INFO creating keypair: Test1-#{uuid}/)
266
+ expect(last_command_started).to have_output(/INFO created keypair: Test1-#{uuid}/)
267
+ expect(last_command_started).not_to have_output(/INFO creating keypair: Test2-#{uuid}/)
268
+ expect(last_command_started).not_to have_output(/INFO created keypair: Test2-#{uuid}/)
269
+ expect(last_command_started).to have_output(/INFO creating keypair: Test3-#{uuid}/)
270
+ expect(last_command_started).to have_output(/INFO created keypair: Test3-#{uuid}/)
271
+ end
272
+ end
273
+ after(:each) { run_command('cfndk destroy -f') }
274
+ end
275
+ end
276
+ end
277
+ end
278
+ end
279
+ end
280
+ end
281
+
282
+ describe 'destroy' do
283
+ context 'without cfndk.yml' do
284
+ before(:each) { run_command('cfndk keypair destroy') }
285
+ it 'displays file does not exist error and status code = 1' do
286
+ aggregate_failures do
287
+ expect(last_command_started).to have_exit_status(1)
288
+ expect(last_command_started).to have_output(/ERROR RuntimeError: File does not exist./)
289
+ end
290
+ end
291
+ end
292
+ context 'with cfndk.yml' do
293
+ context 'when cfndk.yml is empty' do
294
+ before(:each) { touch(file) }
295
+ before(:each) { run_command('cfndk keypair destroy -f') }
296
+ it 'displays File is empty error and status code = 1' do
297
+ aggregate_failures do
298
+ expect(last_command_started).to have_exit_status(1)
299
+ expect(last_command_started).to have_output(/ERROR File is empty./)
300
+ end
301
+ end
302
+ end
303
+ context 'when enter no' do
304
+ yaml = <<-"YAML"
305
+ keypairs:
306
+ Test1:
307
+ stacks:
308
+ Test:
309
+ template_file: vpc.yaml
310
+ parameter_input: vpc.json
311
+ parameters:
312
+ VpcName: sample<%= append_uuid%>
313
+ timeout_in_minutes: 2
314
+ YAML
315
+ before(:each) { write_file(file, yaml) }
316
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
317
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
318
+ before(:each) { run_command('cfndk keypair destroy') }
319
+ before(:each) { type('no') }
320
+ it 'displays confirm message and cancel message and status code = 2' do
321
+ aggregate_failures do
322
+ expect(last_command_started).to have_exit_status(2)
323
+ expect(last_command_started).to have_output(/INFO destroy../)
324
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
325
+ expect(last_command_started).to have_output(/INFO destroy command was canceled/)
326
+ expect(last_command_started).not_to have_output(/INFO deleting stack:/)
327
+ expect(last_command_started).not_to have_output(/INFO deleted stack:/)
328
+ expect(last_command_started).not_to have_output(/INFO do not delete keypair: Test1$/)
329
+ expect(last_command_started).not_to have_output(/INFO do not delete stack: Test$/)
330
+ end
331
+ end
332
+ end
333
+ context 'when enter yes' do
334
+ context 'when keyparis do not exist' do
335
+ yaml = <<-"YAML"
336
+ keypairs:
337
+ Test1:
338
+ stacks:
339
+ Test:
340
+ template_file: vpc.yaml
341
+ parameter_input: vpc.json
342
+ parameters:
343
+ VpcName: sample<%= append_uuid%>
344
+ timeout_in_minutes: 2
345
+ YAML
346
+ before(:each) { write_file(file, yaml) }
347
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
348
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
349
+ before(:each) { run_command_and_stop('cfndk destroy -f') }
350
+ before(:each) { run_command('cfndk keypair destroy') }
351
+ before(:each) { type('yes') }
352
+ it 'displays confirm message and do not delete message' do
353
+ aggregate_failures do
354
+ expect(last_command_started).to be_successfully_executed
355
+ expect(last_command_started).to have_output(/INFO destroy../)
356
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
357
+ expect(last_command_started).to have_output(/INFO do not delete keypair: Test1$/)
358
+ expect(last_command_started).not_to have_output(/INFO do not delete stack: Test$/)
359
+ end
360
+ end
361
+ end
362
+ context 'when keyparis and stacks exist' do
363
+ yaml = <<-"YAML"
364
+ keypairs:
365
+ Test1:
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
+ YAML
374
+ before(:each) { write_file(file, yaml) }
375
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
376
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
377
+ before(:each) { run_command('cfndk create') }
378
+ before(:each) { stop_all_commands }
379
+ before(:each) { run_command('cfndk keypair destroy') }
380
+ before(:each) { type('yes') }
381
+ it 'displays confirm message and delete message' do
382
+ aggregate_failures do
383
+ expect(last_command_started).to be_successfully_executed
384
+ expect(last_command_started).to have_output(/INFO destroy../)
385
+ expect(last_command_started).to have_output(%r{Are you sure you want to destroy\? \(y/n\)})
386
+ expect(last_command_started).to have_output(/INFO deleted keypair: Test1$/)
387
+ expect(last_command_started).not_to have_output(/INFO deleted stack: Test$/)
388
+ end
389
+ end
390
+ after(:each) { run_command('cfndk destroy -f') }
391
+ end
392
+ end
393
+ end
394
+ end
395
+ end
396
+ end
397
+ end