Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix tests
Fix AWS environment variable names in tests.
Fix AWS variables coupling: id and secret must both be present.
Updated code to work together with finalize defaults.
Set tests to run with defined order, making debugging easier.
  • Loading branch information
alexconst committed Feb 4, 2016
1 parent 66adb1c commit cb922a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Rakefile
Expand Up @@ -15,7 +15,8 @@ Dir.chdir(File.expand_path("../", __FILE__))
Bundler::GemHelper.install_tasks

# Install the `spec` task so that we can run tests.
RSpec::Core::RakeTask.new

RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = "--order defined"
end
# Default task is to run the unit tests
task :default => "spec"
task :default => :spec
7 changes: 4 additions & 3 deletions lib/vagrant-aws/config.rb
Expand Up @@ -321,12 +321,12 @@ def finalize!
# the AWS folder.
if @access_key_id == UNSET_VALUE or @secret_access_key == UNSET_VALUE
@aws_profile = 'default' if @aws_profile == UNSET_VALUE
@aws_dir = ENV['HOME'] + '/.aws/' if @aws_dir == UNSET_VALUE
@aws_dir = ENV['HOME'].to_s + '/.aws/' if @aws_dir == UNSET_VALUE
@region, @access_key_id, @secret_access_key, @session_token = Credentials.new.get_aws_info(@aws_profile, @aws_dir)
@region = UNSET_VALUE if @region.nil?
else
@aws_profile = nil
@aws_dir = nil
@session_token = nil
end

# AMI must be nil, since we can't default that
Expand Down Expand Up @@ -490,7 +490,8 @@ def get_aws_info(profile, location)
# read from environment variables
aws_region, aws_id, aws_secret, aws_token = read_aws_environment()
# if nothing there, then read from files
if aws_id.to_s == '' or aws_secret.to_s == '' or aws_region.to_s == ''
# it doesn't check aws_region since Config#finalize sets one by default
if aws_id.to_s == '' or aws_secret.to_s == ''
aws_region, aws_id, aws_secret, aws_token = read_aws_files(profile, location)
end
aws_region = nil if aws_region == ''
Expand Down
10 changes: 8 additions & 2 deletions spec/vagrant-aws/config_spec.rb
Expand Up @@ -62,6 +62,10 @@
:source_dest_check].each do |attribute|

it "should not default #{attribute} if overridden" do
# but these should always come together, so you need to set them all or nothing
instance.send("access_key_id=".to_sym, "foo")
instance.send("secret_access_key=".to_sym, "foo")
instance.send("session_token=".to_sym, "foo")
instance.send("#{attribute}=".to_sym, "foo")
instance.finalize!
instance.send(attribute).should == "foo"
Expand Down Expand Up @@ -89,8 +93,8 @@

context "with EC2 credential environment variables" do
before :each do
ENV.stub(:[]).with("AWS_ACCESS_KEY").and_return("access_key")
ENV.stub(:[]).with("AWS_SECRET_KEY").and_return("secret_key")
ENV.stub(:[]).with("AWS_ACCESS_KEY_ID").and_return("access_key")
ENV.stub(:[]).with("AWS_SECRET_ACCESS_KEY").and_return("secret_key")
ENV.stub(:[]).with("AWS_SESSION_TOKEN").and_return("session_token")
end

Expand Down Expand Up @@ -187,6 +191,7 @@ def set_test_values(instance)

# Set some top-level values
instance.access_key_id = "parent"
instance.secret_access_key = "parent"
instance.ami = "parent"

# Finalize and get the region
Expand All @@ -195,6 +200,7 @@ def set_test_values(instance)
end

its("access_key_id") { should == "parent" }
its("secret_access_key") { should == "parent" }
its("ami") { should == "child" }
end

Expand Down

0 comments on commit cb922a9

Please sign in to comment.