Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validation when spot-wait-mode option is given by user on CLI and spot-price option is not given. #429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,11 @@ def validate!
exit 1
end

if locate_config_value(:spot_price).nil? && locate_config_value(:spot_wait_mode).downcase != 'prompt'
ui.error('spot-wait-mode option requires that a spot-price option is set.')
exit 1
end

end

def tags
Expand Down
60 changes: 60 additions & 0 deletions spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,66 @@
expect(@new_ec2_server).to receive(:wait_for).and_return(true)
@knife_ec2_create.run
end

context 'spot-wait-mode option' do
context 'when spot-price is not given' do
context 'spot-wait-mode option is not given' do
before do
@knife_ec2_create.config.delete(:spot_price)
end

it 'does not raise error' do
expect(@knife_ec2_create.ui).to_not receive(:error).with(
'spot-wait-mode option requires that a spot-price option is set.'
)
expect { @knife_ec2_create.validate! }.to_not raise_error
end
end

context 'spot-wait-mode option is given' do
before do
@knife_ec2_create.config.delete(:spot_price)
@knife_ec2_create.config[:spot_wait_mode] = 'wait'
end

it 'raises error' do
expect(@knife_ec2_create.ui).to receive(:error).with(
'spot-wait-mode option requires that a spot-price option is set.'
)
expect { @knife_ec2_create.validate! }.to raise_error(SystemExit)
end
end
end

context 'when spot-price is given' do
context 'spot-wait-mode option is not given' do
before do
@knife_ec2_create.config[:spot_price] = 0.001
end

it 'does not raise error' do
expect(@knife_ec2_create.ui).to_not receive(:error).with(
'spot-wait-mode option requires that a spot-price option is set.'
)
expect { @knife_ec2_create.validate! }.to_not raise_error
end
end

context 'spot-wait-mode option is given' do
before do
@knife_ec2_create.config[:spot_price] = 0.001
@knife_ec2_create.config[:spot_wait_mode] = 'exit'
end

it 'does not raise error' do
expect(@knife_ec2_create.ui).to_not receive(:error).with(
'spot-wait-mode option requires that a spot-price option is set.'
)
expect { @knife_ec2_create.validate! }.to_not raise_error
end
end
end
end
end

describe "run" do
Expand Down