Import action
This commit is contained in:
parent
e77c780e0d
commit
1a89e50da7
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue