From 714c94780c9fc585c5cc5b2a35ac833eca60296d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 12 Sep 2010 16:34:49 -0600 Subject: [PATCH] On import, only run destroy action if VM is created --- lib/vagrant/action/vm/import.rb | 6 ++++-- test/vagrant/action/vm/import_test.rb | 14 +++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index 8c936a67f..f4b009303 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -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 diff --git a/test/vagrant/action/vm/import_test.rb b/test/vagrant/action/vm/import_test.rb index a7ef57726..8c2caa785 100644 --- a/test/vagrant/action/vm/import_test.rb +++ b/test/vagrant/action/vm/import_test.rb @@ -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