2011-03-30 19:50:35 -04:00
|
|
|
Shindo.tests do
|
|
|
|
before do
|
2011-09-23 17:43:34 -04:00
|
|
|
@old_home = ENV['HOME']
|
|
|
|
@old_rc = ENV['FOG_RC']
|
|
|
|
@old_credential = ENV['FOG_CREDENTIAL']
|
2011-09-23 17:44:39 -04:00
|
|
|
@old_credentials = Fog.credentials
|
2011-03-30 19:50:35 -04:00
|
|
|
Fog.instance_variable_set('@credential_path', nil) # kill memoization
|
2011-09-10 13:42:55 -04:00
|
|
|
Fog.instance_variable_set('@credential', nil) # kill memoization
|
2011-03-30 19:50:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2011-09-23 17:43:34 -04:00
|
|
|
ENV['HOME'] = @old_home
|
|
|
|
ENV['FOG_RC'] = @old_rc
|
|
|
|
ENV['FOG_CREDENTIAL'] = @old_credential
|
2011-09-23 17:44:39 -04:00
|
|
|
Fog.credentials = @old_credentials
|
2011-09-10 13:42:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('credential') do
|
|
|
|
returns(:default, "is :default") { Fog.credential }
|
|
|
|
|
2011-11-16 12:51:43 -05:00
|
|
|
returns(:foo, "can be set directly") do
|
2011-09-10 13:42:55 -04:00
|
|
|
Fog.credential = "foo"
|
|
|
|
Fog.credential
|
|
|
|
end
|
|
|
|
|
2011-11-16 12:51:43 -05:00
|
|
|
returns(:bar, "can be set with environment variable") do
|
2011-09-10 13:42:55 -04:00
|
|
|
ENV["FOG_CREDENTIAL"] = "bar"
|
|
|
|
Fog.credential
|
|
|
|
end
|
2011-03-30 19:50:35 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-05-13 18:14:32 -04:00
|
|
|
returns(File.join(ENV['HOME'], '.fog'), 'falls back to home path if FOG_RC not set') {
|
2011-03-30 19:50:35 -04:00
|
|
|
ENV.delete('FOG_RC')
|
|
|
|
Fog.credentials_path
|
|
|
|
}
|
|
|
|
|
2011-05-13 18:14:32 -04:00
|
|
|
returns(nil, 'ignores home path if it does not exist') {
|
|
|
|
ENV.delete('FOG_RC')
|
|
|
|
ENV['HOME'] = '/no/such/path'
|
|
|
|
Fog.credentials_path
|
|
|
|
}
|
|
|
|
|
2011-07-13 14:17:00 -04:00
|
|
|
returns(nil, 'File.expand_path raises because of non-absolute path') {
|
|
|
|
ENV.delete('FOG_RC')
|
|
|
|
ENV['HOME'] = '.'
|
2013-10-24 15:17:51 -04:00
|
|
|
|
|
|
|
if RUBY_PLATFORM == 'java'
|
|
|
|
Fog::Logger.warning("Stubbing out non-absolute path credentials test due to JRuby bug: https://github.com/jruby/jruby/issues/1163")
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
Fog.credentials_path
|
|
|
|
end
|
2011-07-13 14:17:00 -04:00
|
|
|
}
|
|
|
|
|
2011-03-30 19:50:35 -04:00
|
|
|
returns(nil, 'returns nil when neither FOG_RC or HOME are set') {
|
|
|
|
ENV.delete('HOME')
|
|
|
|
ENV.delete('FOG_RC')
|
|
|
|
Fog.credentials_path
|
|
|
|
}
|
|
|
|
end
|
2013-08-13 16:57:08 -04:00
|
|
|
|
|
|
|
tests('symbolize_credential?') do
|
|
|
|
returns(true, "username") { Fog.symbolize_credential?(:username) }
|
|
|
|
returns(false, "headers") { Fog.symbolize_credential?(:headers) }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('symbolize_credentials') do
|
|
|
|
h = {
|
|
|
|
"a" => 3,
|
|
|
|
:something => 2,
|
|
|
|
"connection_options" => {"val" => 5},
|
|
|
|
:headers => { 'User-Agent' => "my user agent" }
|
|
|
|
}
|
|
|
|
|
|
|
|
returns({
|
|
|
|
:a => 3,
|
|
|
|
:something => 2,
|
|
|
|
:connection_options => {:val => 5},
|
|
|
|
:headers => { 'User-Agent' => "my user agent" }
|
|
|
|
}) { Fog.symbolize_credentials h }
|
|
|
|
end
|
2011-03-30 19:50:35 -04:00
|
|
|
end
|