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: :ssh:
:uname: hobo :uname: hobo
:pass: hobo :pass: hobo
:host: localhost :host: localhost
:vm:
:base: ~/.hobo/base/base.ovf

View File

@ -1,5 +1,5 @@
libdir = File.dirname(__FILE__) libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) $:.unshift(libdir)
PROJECT_ROOT = File.join(libdir, '..') PROJECT_ROOT = File.join(libdir, '..')
require 'ostruct' require 'ostruct'
@ -10,5 +10,6 @@ require 'hobo/env'
require 'hobo/ssh' require 'hobo/ssh'
# TODO: Make this configurable # 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 Hobo::Env.load_config

View File

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

View File

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

View File

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

View File

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