From 179a788fe33c257b4310dd16191bba79826a0fc7 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Thu, 30 May 2013 13:35:37 -0700 Subject: [PATCH] start a ruby version of aws-ha-release - use aruba to test command line options - use rspec to unit test --- .gitignore | 3 +- Gemfile | 6 +++ Gemfile.lock | 45 ++++++++++++++++++++++ aws-ha-release/aws-ha-release.rb | 22 +++++++++++ features/aws-ha-release.feature | 41 ++++++++++++++++++++ features/support/env.rb | 3 ++ spec/aws-ha-release/aws-ha-release_spec.rb | 5 +++ 7 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 aws-ha-release/aws-ha-release.rb create mode 100644 features/aws-ha-release.feature create mode 100644 features/support/env.rb create mode 100644 spec/aws-ha-release/aws-ha-release_spec.rb diff --git a/.gitignore b/.gitignore index 7d289b4..cdb4868 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # OS generated files # ###################### -.DS_Store \ No newline at end of file +.DS_Store +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4be8c17 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org' + +gem 'aws-sdk' +gem 'trollop' +gem 'rspec' +gem 'aruba' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..65e1dd1 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/aws-ha-release/aws-ha-release.rb b/aws-ha-release/aws-ha-release.rb new file mode 100755 index 0000000..8b1512b --- /dev/null +++ b/aws-ha-release/aws-ha-release.rb @@ -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 ' 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 .' 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 .' if opts[:aws_access_key] && opts[:aws_secret_key].nil? diff --git a/features/aws-ha-release.feature b/features/aws-ha-release.feature new file mode 100644 index 0000000..cc4a23a --- /dev/null +++ b/features/aws-ha-release.feature @@ -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 " + 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 diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..440d9cf --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,3 @@ +require 'aruba/cucumber' + +ENV['PATH'] = "#{Dir.pwd}/aws-ha-release#{File::PATH_SEPARATOR}#{ENV['PATH']}" diff --git a/spec/aws-ha-release/aws-ha-release_spec.rb b/spec/aws-ha-release/aws-ha-release_spec.rb new file mode 100644 index 0000000..1d5de30 --- /dev/null +++ b/spec/aws-ha-release/aws-ha-release_spec.rb @@ -0,0 +1,5 @@ +require 'rspec' +require File.expand_path('aws-ha-release/aws-ha-release.rb') + +describe 'aws-ha-release' do +end