65 lines
1.7 KiB
Ruby
65 lines
1.7 KiB
Ruby
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
|
|
class VMTest < Test::Unit::TestCase
|
|
setup do
|
|
@mock_vm = mock("vm")
|
|
mock_config
|
|
|
|
@persisted_vm = mock("persisted_vm")
|
|
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
|
|
|
Net::SSH.stubs(:start)
|
|
end
|
|
|
|
context "finding a VM" do
|
|
should "return nil if the VM is not found" do
|
|
VirtualBox::VM.expects(:find).returns(nil)
|
|
assert_nil Vagrant::VM.find("foo")
|
|
end
|
|
|
|
should "return a Vagrant::VM object for that VM otherwise" do
|
|
VirtualBox::VM.expects(:find).with("foo").returns("bar")
|
|
result = Vagrant::VM.find("foo")
|
|
assert result.is_a?(Vagrant::VM)
|
|
assert_equal "bar", result.vm
|
|
end
|
|
end
|
|
|
|
context "vagrant VM instance" do
|
|
setup do
|
|
@vm = Vagrant::VM.new(@mock_vm)
|
|
end
|
|
|
|
context "destroying" do
|
|
setup do
|
|
@mock_vm.stubs(:running?).returns(false)
|
|
@vm.stubs(:execute!)
|
|
end
|
|
|
|
should "destoy the VM along with images" do
|
|
@mock_vm.expects(:destroy).with(:destroy_image => true).once
|
|
@vm.destroy
|
|
end
|
|
|
|
should "stop the VM if its running" do
|
|
@mock_vm.expects(:running?).returns(true)
|
|
@mock_vm.expects(:destroy).with(:destroy_image => true).once
|
|
@vm.expects(:execute!).with(Vagrant::Actions::Stop).once
|
|
@vm.destroy
|
|
end
|
|
end
|
|
|
|
context "saving the state" do
|
|
should "check if a VM is saved" do
|
|
@mock_vm.expects(:saved?).returns("foo")
|
|
assert_equal "foo", @vm.saved?
|
|
end
|
|
|
|
should "save state with errors raised" do
|
|
@mock_vm.expects(:save_state).with(true).once
|
|
@vm.save_state
|
|
end
|
|
end
|
|
end
|
|
end
|