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