use ruby optionparser instead of trollop

remove cucumber
This commit is contained in:
Anuj Biyani
2013-06-04 15:18:18 -07:00
parent 601f6087ec
commit 29aeb75ca3
8 changed files with 112 additions and 120 deletions

View File

@@ -1,16 +1,7 @@
require 'spec_helper'
describe 'aws-ha-release' do
let(:opts) do
{
as_group_name: 'test_group',
aws_access_key: 'testaccesskey',
aws_secret_key: 'testsecretkey',
region: 'test-region',
inservice_time_allowed: 300,
elb_timeout: 0
}
end
let(:opts) { %w(-a test_group -o testaccesskey -s testsecretkey -r test_region -i 1 -t 0) }
let(:as) { AWS::FakeAutoScaling.new }
@@ -25,22 +16,69 @@ describe 'aws-ha-release' do
describe '#initialize' do
it 'initializes the AWS connection' do
as.groups.create opts[:as_group_name]
as.groups.create opts[1]
AWS.should_receive(:config).with(access_key_id: 'testaccesskey', secret_access_key: 'testsecretkey', region: 'test-region')
AWS.should_receive(:config).with(access_key_id: 'testaccesskey', secret_access_key: 'testsecretkey', region: 'test_region')
AwsHaRelease.new(opts)
end
it 'ensures the as group exists' do
lambda {
AwsHaRelease.new(opts.merge!(as_group_name: 'fake_group'))
opts[1] = 'fake_group'
AwsHaRelease.new(opts)
}.should raise_error
end
end
describe '#parse_options' do
it 'requires the autoscaling group name to be passed in' do
expect{ AwsHaRelease.parse_options([]) }.to raise_error OptionParser::MissingArgument
expect(AwsHaRelease.parse_options(%w(-a test_group))[:as_group_name]).to eq 'test_group'
expect(AwsHaRelease.parse_options(%w(--as-group-name test_group))[:as_group_name]).to eq 'test_group'
end
it 'sets default options' do
options = AwsHaRelease.parse_options(%w(-a test_group))
expect(options[:elb_timeout]).not_to be_nil
expect(options[:region]).not_to be_nil
expect(options[:inservice_time_allowed]).not_to be_nil
expect(options[:aws_access_key]).not_to be_nil
expect(options[:aws_secret_key]).not_to be_nil
end
context 'optional params' do
it 'ELB timeout' do
[%w(-a test_group -t 10), %w(-a test_group --elb-timeout 10)].each do |options|
expect(AwsHaRelease.parse_options(options)[:elb_timeout]).to eq 10
end
end
it 'region' do
[%w(-a test_group -r test_region), %w(-a test_group --region test_region)].each do |options|
expect(AwsHaRelease.parse_options(options)[:region]).to eq 'test_region'
end
end
it 'inservice time allowed' do
[%w(-a test_group -i 300), %w(-a test_group --inservice-time-allowed 300)].each do |options|
expect(AwsHaRelease.parse_options(options)[:inservice_time_allowed]).to eq 300
end
end
it 'aws_access_key and aws_secret_key' do
expect{ AwsHaRelease.parse_options(%w(-a test_group -o testkey)) }.to raise_error OptionParser::MissingArgument
expect{ AwsHaRelease.parse_options(%w(-a test_group -s testsecretkey)) }.to raise_error OptionParser::MissingArgument
options = AwsHaRelease.parse_options(%w(-a test_group -o testkey -s testsecretkey))
expect(options[:aws_access_key]).to eq 'testkey'
expect(options[:aws_secret_key]).to eq 'testsecretkey'
end
end
end
describe '#execute!' do
before do
@group = as.groups.create opts[:as_group_name]
@group = as.groups.create opts[1]
@aws_ha_release = AwsHaRelease.new(opts)
end
@@ -74,7 +112,7 @@ describe 'aws-ha-release' do
describe 'determining if instances are in service' do
before do
@group = as.groups.create opts[:as_group_name]
@group = as.groups.create opts[1]
@group.update(desired_capacity: 2)
@aws_ha_release = AwsHaRelease.new(opts)
end
@@ -155,7 +193,7 @@ describe 'aws-ha-release' do
describe '#deregister_instance' do
before do
@group = as.groups.create opts[:as_group_name]
@group = as.groups.create opts[1]
@aws_ha_release = AwsHaRelease.new(opts)
end