hobo-down and Env.require_persisted_vm
This commit is contained in:
parent
a394f1cd5f
commit
4cffa15d4e
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env ruby
|
||||
begin
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get hobo
|
||||
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(hobodir) unless $:.include?(hobodir)
|
||||
require 'hobo'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "destroys the hobo environment"
|
||||
banner <<-EOS
|
||||
Usage: #{command.full_name} #{all_options_string}
|
||||
|
||||
Destroys the hobo environment.
|
||||
|
||||
EOS
|
||||
|
||||
run do |command|
|
||||
Hobo::VM.down
|
||||
end
|
||||
end
|
|
@ -80,6 +80,18 @@ msg
|
|||
load_root_path!(path.parent)
|
||||
end
|
||||
|
||||
def require_persisted_vm
|
||||
if !persisted_vm
|
||||
error_and_exit(<<-error)
|
||||
The task you're trying to run requires that the hobo environment
|
||||
already be created, but unfortunately this hobo still appears to
|
||||
have no box! You can setup the environment by setting up your
|
||||
Hobofile and running `hobo up`
|
||||
error
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def error_and_exit(error)
|
||||
puts <<-error
|
||||
=====================================================================
|
||||
|
|
|
@ -11,6 +11,14 @@ module Hobo
|
|||
setup_shared_folder(vm)
|
||||
end
|
||||
|
||||
# Tear down a virtual machine.
|
||||
def down
|
||||
Env.require_persisted_vm
|
||||
|
||||
HOBO_LOGGER.info "Destroying VM and associated drives..."
|
||||
Env.persisted_vm.destroy(:destroy_image => true)
|
||||
end
|
||||
|
||||
def import
|
||||
HOBO_LOGGER.info "Importing base VM (#{Hobo.config[:vm][:base]})..."
|
||||
VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base]))
|
||||
|
|
|
@ -14,10 +14,32 @@ class EnvTest < Test::Unit::TestCase
|
|||
"#{dir}/#{hobo_mock_config[:dotfile_name]}"
|
||||
end
|
||||
|
||||
def mock_persisted_vm(returnvalue="foovm")
|
||||
filemock = mock("filemock")
|
||||
filemock.expects(:read).returns("foo")
|
||||
VirtualBox::VM.expects(:find).with("foo").returns(returnvalue)
|
||||
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
|
||||
Hobo::Env.load_vm!
|
||||
end
|
||||
|
||||
setup do
|
||||
Hobo::Env.stubs(:error_and_exit)
|
||||
end
|
||||
|
||||
context "requiring a VM" do
|
||||
should "error and exit if no persisted VM was found" do
|
||||
assert_nil Hobo::Env.persisted_vm
|
||||
Hobo::Env.expects(:error_and_exit).once
|
||||
Hobo::Env.require_persisted_vm
|
||||
end
|
||||
|
||||
should "return and continue if persisted VM is found" do
|
||||
mock_persisted_vm
|
||||
Hobo::Env.expects(:error_and_exit).never
|
||||
Hobo::Env.require_persisted_vm
|
||||
end
|
||||
end
|
||||
|
||||
context "initial load" do
|
||||
test "load! should load the config and set the persisted_uid" do
|
||||
Hobo::Env.expects(:load_config!).once
|
||||
|
@ -101,12 +123,7 @@ class EnvTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
test "loading of the uuid from the dotfile" do
|
||||
VirtualBox::VM.expects(:find).with("foo").returns("foovm")
|
||||
|
||||
filemock = mock("filemock")
|
||||
filemock.expects(:read).returns("foo")
|
||||
File.expects(:open).with(Hobo::Env.dotfile_path).once.yields(filemock)
|
||||
Hobo::Env.load_vm!
|
||||
mock_persisted_vm
|
||||
assert_equal 'foovm', Hobo::Env.persisted_vm
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,24 @@ class VMTest < Test::Unit::TestCase
|
|||
Hobo.config!(hobo_mock_config)
|
||||
end
|
||||
|
||||
context "hobo down" do
|
||||
setup do
|
||||
@persisted_vm = mock("persisted_vm")
|
||||
@persisted_vm.stubs(:destroy)
|
||||
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
||||
end
|
||||
|
||||
should "require a persisted VM" do
|
||||
Hobo::Env.expects(:require_persisted_vm).once
|
||||
Hobo::VM.down
|
||||
end
|
||||
|
||||
should "destroy the persisted VM and the VM image" do
|
||||
@persisted_vm.expects(:destroy).with(:destroy_image => true).once
|
||||
Hobo::VM.down
|
||||
end
|
||||
end
|
||||
|
||||
context "hobo up" do
|
||||
should "create the instance in the proper order" do
|
||||
create_seq = sequence("create_seq")
|
||||
|
|
Loading…
Reference in New Issue