start a ruby version of aws-ha-release

- use aruba to test command line options
  - use rspec to unit test
This commit is contained in:
Anuj Biyani 2013-05-30 13:35:37 -07:00
parent 64e840e711
commit 179a788fe3
7 changed files with 124 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
# OS generated files # # OS generated files #
###################### ######################
.DS_Store .DS_Store
tmp

6
Gemfile Normal file
View File

@ -0,0 +1,6 @@
source 'https://rubygems.org'
gem 'aws-sdk'
gem 'trollop'
gem 'rspec'
gem 'aruba'

45
Gemfile.lock Normal file
View File

@ -0,0 +1,45 @@
GEM
remote: https://rubygems.org/
specs:
aruba (0.5.3)
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
rspec-expectations (>= 2.7.0)
aws-sdk (1.8.5)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
builder (3.2.1)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
cucumber (1.3.2)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12.0)
multi_json (~> 1.3)
diff-lcs (1.1.3)
ffi (1.8.1)
gherkin (2.12.0)
multi_json (~> 1.3)
json (1.7.7)
multi_json (1.7.4)
nokogiri (1.5.9)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
trollop (2.0)
uuidtools (2.1.3)
PLATFORMS
ruby
DEPENDENCIES
aruba
aws-sdk
rspec
trollop

View File

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
begin
require 'aws-sdk'
require 'trollop'
rescue LoadError => e
puts "The #{e.message.split('-').last.strip} gem must be installed."
raise
end
opts = Trollop::options do
opt :as_group_name, 'AutoScaling Group Name', type: :string, short: '-a'
opt :region, 'Region', type: :string, short: '-r'
opt :elb_timeout, 'ELB Timeout', type: :int, default: 60, short: '-t'
opt :inservice_time_allowed, 'InService Time Allowed', type: :int, default: 300, short: '-i'
opt :aws_access_key, 'AWS Access Key', type: :string, short: '-o'
opt :aws_secret_key, 'AWS Secret Key', type: :string, short: '-s'
end
Trollop::die :as_group_name, 'You must specify the AutoScaling Group Name: aws-ha-release.rb -a <group name>' unless opts[:as_group_name]
Trollop::die :aws_access_key, 'If you specify the AWS Secret Key, you must also specify the Access Key with -o <key>.' if opts[:aws_secret_key] && opts[:aws_access_key].nil?
Trollop::die :aws_secret_key, 'If you specify the AWS Access Key, you must also specify the Secret Key with -s <key>.' if opts[:aws_access_key] && opts[:aws_secret_key].nil?

View File

@ -0,0 +1,41 @@
Feature: AWS High-Availibility Release
Scenario: Requires the autoscaling group name to be passed in
When I run `aws-ha-release.rb`
Then the output should contain "You must specify the AutoScaling Group Name: aws-ha-release.rb -a <group name>"
And the exit status should not be 0
When I run `aws-ha-release.rb -a test_group`
Then the exit status should be 0
When I run `aws-ha-release.rb --as-group-name test_group`
Then the exit status should be 0
Scenario: Optionally allows the user to specify an ELB timeout
When I run `aws-ha-release.rb -a test_group -t not_valid_input`
Then the exit status should not be 0
When I run `aws-ha-release.rb -a test_group -t 100`
Then the exit status should be 0
When I run `aws-ha-release.rb -a test_group --elb-timeout 100`
Then the exit status should be 0
Scenario: Optionally allows the user to specify a region
When I run `aws-ha-release.rb -a test_group -r`
Then the exit status should not be 0
When I run `aws-ha-release.rb -a test_group -r test_region`
Then the exit status should be 0
When I run `aws-ha-release.rb -a test_group --region test_region`
Then the exit status should be 0
Scenario: Optionally allows the user to specify an inservice time allowed
When I run `aws-ha-release.rb -a test_group -i not_valid_input`
Then the exit status should not be 0
When I run `aws-ha-release.rb -a test_group -i 100`
Then the exit status should be 0
When I run `aws-ha-release.rb -a test_group --inservice-time-allowed 100`
Then the exit status should be 0
Scenario: Optionally allows the user to pass in the aws_access_key and aws_secret_key
When I run `aws-ha-release.rb -a test_group -o testaccesskey`
Then the exit status should not be 0
When I run `aws-ha-release.rb -a test_group -o testaccesskey -s testsecretkey`
Then the exit status should be 0
When I run `aws-ha-release.rb -a test_group --aws-access-key testaccesskey --aws-secret-key testsecretkey`
Then the exit status should be 0

3
features/support/env.rb Normal file
View File

@ -0,0 +1,3 @@
require 'aruba/cucumber'
ENV['PATH'] = "#{Dir.pwd}/aws-ha-release#{File::PATH_SEPARATOR}#{ENV['PATH']}"

View File

@ -0,0 +1,5 @@
require 'rspec'
require File.expand_path('aws-ha-release/aws-ha-release.rb')
describe 'aws-ha-release' do
end