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.
This commit is contained in:
parent
66adb1c62c
commit
cb922a9bf1
7
Rakefile
7
Rakefile
|
@ -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
|
||||
|
|
|
@ -321,12 +321,12 @@ module VagrantPlugins
|
|||
# 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
|
||||
|
@ -490,7 +490,8 @@ module VagrantPlugins
|
|||
# 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 == ''
|
||||
|
|
|
@ -62,6 +62,10 @@ describe VagrantPlugins::AWS::Config do
|
|||
: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"
|
||||
|
@ -89,8 +93,8 @@ describe VagrantPlugins::AWS::Config do
|
|||
|
||||
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
|
||||
|
||||
|
@ -187,6 +191,7 @@ describe VagrantPlugins::AWS::Config do
|
|||
|
||||
# Set some top-level values
|
||||
instance.access_key_id = "parent"
|
||||
instance.secret_access_key = "parent"
|
||||
instance.ami = "parent"
|
||||
|
||||
# Finalize and get the region
|
||||
|
@ -195,6 +200,7 @@ describe VagrantPlugins::AWS::Config do
|
|||
end
|
||||
|
||||
its("access_key_id") { should == "parent" }
|
||||
its("secret_access_key") { should == "parent" }
|
||||
its("ami") { should == "child" }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue