Logging environments (silence for tests) and some test refactor

This commit is contained in:
Mitchell Hashimoto 2010-01-29 20:38:36 -08:00
parent f1e16f6518
commit ed22b555f4
6 changed files with 28 additions and 17 deletions

View File

@ -1,4 +1,7 @@
:ssh:
:uname: hobo
:pass: hobo
:host: localhost
:host: localhost
:vm:
:base: ~/.hobo/base/base.ovf

View File

@ -1,5 +1,5 @@
libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
$:.unshift(libdir)
PROJECT_ROOT = File.join(libdir, '..')
require 'ostruct'
@ -10,5 +10,6 @@ require 'hobo/env'
require 'hobo/ssh'
# TODO: Make this configurable
HOBO_LOGGER = Logger.new(STDOUT)
log_output = ENV['HOBO_ENV'] == 'test' ? nil : STDOUT
HOBO_LOGGER = Logger.new(log_output)
Hobo::Env.load_config

View File

@ -25,6 +25,8 @@ module Hobo
def load_config
ensure_directories
ensure_files
HOBO_LOGGER.info "Loading config from #{CONFIG.keys.first}"
parsed = block_given? ? yield(CONFIG.keys.first) : YAML.load_file(CONFIG.keys.first)
Hobo.config!(parsed)
end

View File

@ -47,15 +47,15 @@ class EnvTest < Test::Unit::TestCase
@handler.expects(:ensure_files).once
@handler.load_config do |file|
assert_equal file, Hobo::Env::CONFIG.keys.first
HOBO_MOCK_CONFIG
hobo_mock_config
end
assert_equal Hobo.config[:ssh], HOBO_MOCK_CONFIG[:ssh]
assert_equal Hobo.config[:ssh], hobo_mock_config[:ssh]
end
test "should default to haml load of the default, without a block" do
YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(HOBO_MOCK_CONFIG)
YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config)
@handler.load_config
assert_equal Hobo.config[:ssh], HOBO_MOCK_CONFIG[:ssh]
assert_equal Hobo.config[:ssh], hobo_mock_config[:ssh]
end
end
end

View File

@ -9,7 +9,7 @@ class SshTest < Test::Unit::TestCase
end
test "should call exec with defaults when no options are supplied" do
ssh = HOBO_MOCK_CONFIG[:ssh]
ssh = hobo_mock_config[:ssh]
Kernel.expects(:exec).with("#{@script} #{ssh[:uname]} #{ssh[:pass]} #{ssh[:host]} #{ssh[:port]}")
Hobo::SSH.connect
end

View File

@ -13,6 +13,8 @@ ENVERR
exit
end
ENV['HOBO_ENV'] = 'test'
# ruby-debug, not necessary, but useful if we have it
begin
require 'ruby-debug'
@ -22,12 +24,15 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'hobo')
require 'contest'
require 'mocha'
HOBO_MOCK_CONFIG =
{ :ssh =>
{
:uname => 'foo',
:pass => 'bar',
:host => 'baz',
:port => 'bak'
}
}
class Test::Unit::TestCase
def hobo_mock_config
{ :ssh =>
{
:uname => 'foo',
:pass => 'bar',
:host => 'baz',
:port => 'bak'
}
}
end
end