1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/core/credential_tests.rb
Aaron Suggs e48ac6e8c3 [core] Allow FOG_CREDENTIAL env variable for config
Say your ~/.fog had multiple stanzas:
    :default:
      :aws_access_key_id: aaa
    test:
      :aws_access_key_id: bbb
    prod:
      :aws_access-key_id: ccc

Choose a stanza with an environment variable:
   $ FOG_CREDENTIAL=prod fog
2011-09-10 13:42:55 -04:00

64 lines
1.6 KiB
Ruby

Shindo.tests do
before do
@old_home = ENV['HOME']
@old_rc = ENV['FOG_RC']
@old_credential = ENV['FOG_CREDENTIAL']
Fog.instance_variable_set('@credential_path', nil) # kill memoization
Fog.instance_variable_set('@credential', nil) # kill memoization
end
after do
ENV['HOME'] = @old_home
ENV['FOG_RC'] = @old_rc
ENV['FOG_CREDENTIAL'] = @old_credential
end
tests('credential') do
returns(:default, "is :default") { Fog.credential }
returns("foo", "can be set directly") do
Fog.credential = "foo"
Fog.credential
end
returns("bar", "can be set with environment variable") do
ENV["FOG_CREDENTIAL"] = "bar"
Fog.credential
end
end
tests('credentials_path') do
returns('/rc/path', 'FOG_RC takes precedence over HOME') {
ENV['HOME'] = '/home/path'
ENV['FOG_RC'] = '/rc/path'
}
returns('/expanded/path', 'properly expands paths') {
ENV['FOG_RC'] = '/expanded/subdirectory/../path'
Fog.credentials_path
}
returns(File.join(ENV['HOME'], '.fog'), 'falls back to home path if FOG_RC not set') {
ENV.delete('FOG_RC')
Fog.credentials_path
}
returns(nil, 'ignores home path if it does not exist') {
ENV.delete('FOG_RC')
ENV['HOME'] = '/no/such/path'
Fog.credentials_path
}
returns(nil, 'File.expand_path raises because of non-absolute path') {
ENV.delete('FOG_RC')
ENV['HOME'] = '.'
Fog.credentials_path
}
returns(nil, 'returns nil when neither FOG_RC or HOME are set') {
ENV.delete('HOME')
ENV.delete('FOG_RC')
Fog.credentials_path
}
end
end