use string for backend conf

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-03 14:56:08 +02:00
parent 21f0a37764
commit f54fa6537a
3 changed files with 30 additions and 30 deletions

View file

@ -15,14 +15,14 @@ module Vulcano
def self.target_config( config )
conf = config.dup
return conf if conf[:target].to_s.empty?
return conf if conf['target'].to_s.empty?
uri = URI::parse(conf[:target].to_s)
conf[:backend] = conf[:backend] || uri.scheme
conf[:host] = conf[:host] || uri.host
conf[:port] = conf[:port] || uri.port
conf[:user] = conf[:user] || uri.user
conf[:password] = conf[:password] || uri.password
uri = URI::parse(conf['target'].to_s)
conf['backend'] = conf['backend'] || uri.scheme
conf['host'] = conf['host'] || uri.host
conf['port'] = conf['port'] || uri.port
conf['user'] = conf['user'] || uri.user
conf['password'] = conf['password'] || uri.password
# return the updated config
conf

View file

@ -9,7 +9,7 @@ module Vulcano::Backends
def initialize(conf)
@conf = conf
@files = {}
type = @conf['backend']
type = @conf['backend'].to_s
configure_shared_options

View file

@ -13,27 +13,27 @@ describe 'Vulcano::Backend' do
describe 'target config helper' do
it 'configures resolves target' do
org = {
target: 'ssh://user:pass@host.com:123'
'target' => 'ssh://user:pass@host.com:123',
}
res = Vulcano::Backend.target_config(org)
res[:backend].must_equal 'ssh'
res[:host].must_equal 'host.com'
res[:user].must_equal 'user'
res[:password].must_equal 'pass'
res[:port].must_equal 123
res[:target].must_equal org[:target]
org.keys.must_equal [:target]
res['backend'].must_equal 'ssh'
res['host'].must_equal 'host.com'
res['user'].must_equal 'user'
res['password'].must_equal 'pass'
res['port'].must_equal 123
res['target'].must_equal org['target']
org.keys.must_equal ['target']
end
it 'resolves a target while keeping existing fields' do
org = {
target: 'ssh://user:pass@host.com:123',
backend: rand,
host: rand,
user: rand,
password: rand,
port: rand,
target: rand,
'target' => 'ssh://user:pass@host.com:123',
'backend' => rand,
'host' => rand,
'user' => rand,
'password' => rand,
'port' => rand,
'target' => rand,
}
res = Vulcano::Backend.target_config(org)
res.must_equal org
@ -41,15 +41,15 @@ describe 'Vulcano::Backend' do
it 'keeps the configuration when incorrect target is supplied' do
org = {
target: 'wrong',
'target' => 'wrong',
}
res = Vulcano::Backend.target_config(org)
res[:backend].must_be_nil
res[:host].must_be_nil
res[:user].must_be_nil
res[:password].must_be_nil
res[:port].must_be_nil
res[:target].must_equal org[:target]
res['backend'].must_be_nil
res['host'].must_be_nil
res['user'].must_be_nil
res['password'].must_be_nil
res['port'].must_be_nil
res['target'].must_equal org['target']
end
end