Hobo::Env now loads the persisted VM as a Hobo::VM object
This commit is contained in:
parent
642c94429e
commit
652a157d51
|
@ -48,7 +48,7 @@ module Hobo
|
|||
|
||||
def load_vm!
|
||||
File.open(dotfile_path) do |f|
|
||||
@@persisted_vm = VirtualBox::VM.find(f.read)
|
||||
@@persisted_vm = Hobo::VM.find(f.read)
|
||||
end
|
||||
rescue Errno::ENOENT
|
||||
@@persisted_vm = nil
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module Hobo
|
||||
class VM
|
||||
attr_reader :vm
|
||||
|
||||
class <<self
|
||||
# Bring up the virtual machine. Imports the base image and
|
||||
# provisions it.
|
||||
|
@ -14,6 +16,14 @@ module Hobo
|
|||
HOBO_LOGGER.info "Destroying VM and associated drives..."
|
||||
Env.persisted_vm.destroy(:destroy_image => true)
|
||||
end
|
||||
|
||||
# Finds a virtual machine by a given UUID and either returns
|
||||
# a Hobo::VM object or returns nil.
|
||||
def find(uuid)
|
||||
vm = VirtualBox::VM.find(uuid)
|
||||
return nil if vm.nil?
|
||||
new(vm)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(vm=nil)
|
||||
|
|
|
@ -17,7 +17,7 @@ class EnvTest < Test::Unit::TestCase
|
|||
def mock_persisted_vm(returnvalue="foovm")
|
||||
filemock = mock("filemock")
|
||||
filemock.expects(:read).returns("foo")
|
||||
VirtualBox::VM.expects(:find).with("foo").returns(returnvalue)
|
||||
Hobo::VM.expects(:find).with("foo").returns(returnvalue)
|
||||
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
|
||||
Hobo::Env.load_vm!
|
||||
end
|
||||
|
|
|
@ -33,6 +33,20 @@ class VMTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "finding a VM" do
|
||||
should "return nil if the VM is not found" do
|
||||
VirtualBox::VM.expects(:find).returns(nil)
|
||||
assert_nil Hobo::VM.find("foo")
|
||||
end
|
||||
|
||||
should "return a Hobo::VM object for that VM otherwise" do
|
||||
VirtualBox::VM.expects(:find).with("foo").returns("bar")
|
||||
result = Hobo::VM.find("foo")
|
||||
assert result.is_a?(Hobo::VM)
|
||||
assert_equal "bar", result.vm
|
||||
end
|
||||
end
|
||||
|
||||
context "hobo VM instance" do
|
||||
setup do
|
||||
@vm = Hobo::VM.new(@mock_vm)
|
||||
|
|
Loading…
Reference in New Issue