diff --git a/lib/vagrant/actions/import.rb b/lib/vagrant/actions/import.rb new file mode 100644 index 000000000..6406e56c5 --- /dev/null +++ b/lib/vagrant/actions/import.rb @@ -0,0 +1,10 @@ +module Vagrant + module Actions + class Import < Base + def execute! + logger.info "Importing base VM (#{Vagrant.config[:vm][:base]})..." + @vm.vm = VirtualBox::VM.import(File.expand_path(Vagrant.config[:vm][:base])) + end + end + end +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index ffe38f2fe..000a60413 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -18,6 +18,7 @@ require 'contest' require 'mocha' class Test::Unit::TestCase + # Clears the previous config and sets up the new config def mock_config Vagrant::Config.instance_variable_set(:@config_runners, nil) Vagrant::Config.instance_variable_set(:@config, nil) @@ -45,4 +46,15 @@ class Test::Unit::TestCase Vagrant::Config.execute! end + + # Sets up the mocks and instantiates an action for testing + def mock_action(action_klass) + @vm = mock("vboxvm") + @mock_vm = mock("vm") + @mock_vm.stubs(:vm).returns(@vm) + @mock_vm.stubs(:vm=) + @action = action_klass.new(@mock_vm) + + [@mock_vm, @vm, @action] + end end diff --git a/test/vagrant/actions/import_test.rb b/test/vagrant/actions/import_test.rb new file mode 100644 index 000000000..ff1dab465 --- /dev/null +++ b/test/vagrant/actions/import_test.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class ImportActionTest < Test::Unit::TestCase + setup do + @mock_vm, @vm, @import = mock_action(Vagrant::Actions::Import) + + VirtualBox::VM.stubs(:import) + end + + should "call import on VirtualBox::VM with the proper base" do + VirtualBox::VM.expects(:import).once + @import.execute! + end + + should "set the resulting VM as the VM of the Vagrant VM object" do + new_vm = mock("new_vm") + @mock_vm.expects(:vm=).with(new_vm).once + VirtualBox::VM.expects(:import).returns(new_vm) + @import.execute! + end +end