"load! load_config! load_uuid! and a persisted_uuid added to Hobo::Env"

This commit is contained in:
John Bender 2010-01-29 23:22:03 -08:00
parent cb63c8c2ae
commit e98e9eba24
4 changed files with 44 additions and 7 deletions

View File

@ -14,4 +14,4 @@ require 'hobo/vm'
# TODO: Make this configurable # TODO: Make this configurable
log_output = ENV['HOBO_ENV'] == 'test' ? nil : STDOUT log_output = ENV['HOBO_ENV'] == 'test' ? nil : STDOUT
HOBO_LOGGER = Logger.new(log_output) HOBO_LOGGER = Logger.new(log_output)
Hobo::Env.load_config Hobo::Env.load! unless ENV['HOBO_ENV'] == 'test'

View File

@ -10,6 +10,11 @@ module Hobo
} }
class << self class << self
def load!
load_config!
load_uuid!
end
def ensure_directories def ensure_directories
ENSURE[:dirs].each do |name| ENSURE[:dirs].each do |name|
Dir.mkdir(name) unless File.exists?(name) Dir.mkdir(name) unless File.exists?(name)
@ -22,7 +27,7 @@ module Hobo
end end
end end
def load_config def load_config!
ensure_directories ensure_directories
ensure_files ensure_files
@ -30,6 +35,15 @@ module Hobo
parsed = YAML.load_file(CONFIG.keys.first) parsed = YAML.load_file(CONFIG.keys.first)
Hobo.config!(parsed) Hobo.config!(parsed)
end end
def load_uuid!
# TODO check multiple lines after the first for information
@@persisted_uuid = File.open(Hobo.config[:dotfile_name], 'r').first
end
def persisted_uuid
@@persisted_uuid
end
end end
end end
end end

View File

@ -43,13 +43,34 @@ class EnvTest < Test::Unit::TestCase
end end
test "should load of the default" do test "should load of the default" do
YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config) config_file_expectation
@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
test "Hobo.config should be nil unless loaded" do test "Hobo.config should be nil unless loaded" do
assert_equal Hobo.config, nil assert_equal Hobo.config, nil
end end
test "loading of the uuid from the dotfile" do
dot_file_expectation
Hobo.config! hobo_mock_config
Hobo::Env.load_uuid!
assert_equal Hobo::Env.persisted_uuid, 'foo'
end
test "load! should load the config and set the persisted_uid" do
dot_file_expectation
config_file_expectation
Hobo::Env.load!
end
def dot_file_expectation
File.expects(:open).with('.hobo', 'r').returns(['foo'])
end
def config_file_expectation
YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config)
end
end end
end end

View File

@ -1,4 +1,4 @@
begin begin
require File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') require File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment')
rescue LoadError rescue LoadError
puts <<-ENVERR puts <<-ENVERR
@ -21,6 +21,7 @@ begin
require 'ruby-debug' require 'ruby-debug'
rescue LoadError; end rescue LoadError; end
require File.join(File.dirname(__FILE__), '..', 'lib', 'hobo') require File.join(File.dirname(__FILE__), '..', 'lib', 'hobo')
require 'contest' require 'contest'
require 'mocha' require 'mocha'
@ -33,7 +34,8 @@ class Test::Unit::TestCase
:pass => 'bar', :pass => 'bar',
:host => 'baz', :host => 'baz',
:port => 'bak' :port => 'bak'
} },
:dotfile_name => '.hobo'
} }
end end
end end