On import, only run destroy action if VM is created

This commit is contained in:
Mitchell Hashimoto 2010-09-12 16:34:49 -06:00
parent 7d73bec776
commit 714c94780c
2 changed files with 13 additions and 7 deletions

View File

@ -22,8 +22,10 @@ module Vagrant
end
def recover(env)
# Interrupted, destroy the VM
env["actions"].run(:destroy)
if env["vm"].created?
# Interrupted, destroy the VM
env["actions"].run(:destroy)
end
end
end
end

View File

@ -40,11 +40,15 @@ class ImportVMActionTest < Test::Unit::TestCase
}
end
should "not run the destroy action on recover if VM is not created" do
@env.env.vm.stubs(:created?).returns(false)
@env.env.actions.expects(:run).never
@instance.recover(@env)
end
should "run the destroy action on recover" do
env = mock("env")
destroy = mock("destory")
env.expects(:[]).with("actions").returns(destroy)
destroy.expects(:run).with(:destroy)
@instance.recover(env)
@env.env.vm.stubs(:created?).returns(true)
@env.env.actions.expects(:run).with(:destroy).once
@instance.recover(@env)
end
end