Test helper `mock_environment` completely gone
This commit is contained in:
parent
d71020ca75
commit
16f3a3face
|
@ -28,73 +28,6 @@ class Test::Unit::TestCase
|
||||||
include VagrantTestHelpers::Environment
|
include VagrantTestHelpers::Environment
|
||||||
include VagrantTestHelpers::Objects
|
include VagrantTestHelpers::Objects
|
||||||
|
|
||||||
# Mocks an environment, setting it up with the given config.
|
|
||||||
def mock_environment
|
|
||||||
environment = Vagrant::Environment.new
|
|
||||||
environment.instance_variable_set(:@loaded, true)
|
|
||||||
|
|
||||||
Vagrant::Config.reset!(environment)
|
|
||||||
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vagrant.home = '~/.home'
|
|
||||||
config.vagrant.dotfile_name = ".vagrant"
|
|
||||||
config.vagrant.log_output = nil
|
|
||||||
config.vagrant.host = :detect
|
|
||||||
|
|
||||||
config.ssh.username = "foo"
|
|
||||||
config.ssh.host = "baz"
|
|
||||||
config.ssh.port = 22
|
|
||||||
config.ssh.forwarded_port_key = "ssh"
|
|
||||||
config.ssh.max_tries = 10
|
|
||||||
config.ssh.timeout = 10
|
|
||||||
config.ssh.private_key_path = File.expand_path("keys/vagrant", Vagrant.source_root)
|
|
||||||
|
|
||||||
config.vm.box = "foo"
|
|
||||||
config.vm.box_url = nil
|
|
||||||
config.vm.box_ovf = "box.ovf"
|
|
||||||
config.vm.base_mac = "42"
|
|
||||||
config.vm.disk_image_format = 'VMDK'
|
|
||||||
config.vm.forward_port("ssh", 22, 2222)
|
|
||||||
config.vm.shared_folder_uid = nil
|
|
||||||
config.vm.shared_folder_gid = nil
|
|
||||||
config.vm.system = :linux
|
|
||||||
config.vm.share_folder("v-root", "/vagrant", ".")
|
|
||||||
|
|
||||||
config.package.name = 'package'
|
|
||||||
|
|
||||||
# Chef
|
|
||||||
config.chef.chef_server_url = "http://localhost:4000"
|
|
||||||
config.chef.validation_key_path = "validation.pem"
|
|
||||||
config.chef.client_key_path = "/zoo/foo/bar.pem"
|
|
||||||
config.chef.node_name = "baz"
|
|
||||||
config.chef.recipe_url = nil
|
|
||||||
config.chef.cookbooks_path = "cookbooks"
|
|
||||||
config.chef.provisioning_path = "/tmp/vagrant-chef"
|
|
||||||
config.chef.log_level = :info
|
|
||||||
config.chef.json = {
|
|
||||||
:recipes => ["vagrant_main"]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
if block_given?
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
yield config
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
config = Vagrant::Config.execute!
|
|
||||||
|
|
||||||
environment.instance_variable_set(:@config, config)
|
|
||||||
|
|
||||||
# Setup the logger. We create it then reset it so that subsequent
|
|
||||||
# calls will recreate it for us.
|
|
||||||
environment.logger.class.reset_singleton_logger!
|
|
||||||
environment.logger.stubs(:flush_progress)
|
|
||||||
environment.logger.stubs(:cl_reset).returns("")
|
|
||||||
|
|
||||||
environment
|
|
||||||
end
|
|
||||||
|
|
||||||
# Sets up the mocks for a VM
|
# Sets up the mocks for a VM
|
||||||
def mock_vm(env=nil)
|
def mock_vm(env=nil)
|
||||||
env ||= vagrant_env
|
env ||= vagrant_env
|
||||||
|
|
|
@ -21,19 +21,11 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
||||||
@instance = @klass.new(@app, @env)
|
@instance = @klass.new(@app, @env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stub_shared_folders
|
def stub_shared_folders(contents)
|
||||||
env = mock_environment do |config|
|
env = vagrant_env(vagrantfile(<<-vf))
|
||||||
config.vm.shared_folders.clear
|
config.vm.shared_folders.clear
|
||||||
|
#{contents}
|
||||||
if block_given?
|
vf
|
||||||
yield config
|
|
||||||
else
|
|
||||||
folders = [%w{foo fooguest foohost}, %w{bar barguest barhost}]
|
|
||||||
folders.each do |data|
|
|
||||||
config.vm.share_folder(*data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@env.stubs(:env).returns(env)
|
@env.stubs(:env).returns(env)
|
||||||
env.config.vm.shared_folders
|
env.config.vm.shared_folders
|
||||||
|
@ -57,11 +49,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
||||||
"bar" => %W[foo baz]
|
"bar" => %W[foo baz]
|
||||||
}
|
}
|
||||||
|
|
||||||
stub_shared_folders do |config|
|
stub_shared_folders(<<-sf)
|
||||||
data.each do |name, value|
|
config.vm.share_folder("foo", "bar", "baz")
|
||||||
config.vm.share_folder(name, *value)
|
config.vm.share_folder("bar", "foo", "baz")
|
||||||
end
|
sf
|
||||||
end
|
|
||||||
|
|
||||||
result = @instance.shared_folders
|
result = @instance.shared_folders
|
||||||
assert_equal data.length, result.length
|
assert_equal data.length, result.length
|
||||||
|
@ -73,20 +64,20 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "ignore disabled shared folders" do
|
should "ignore disabled shared folders" do
|
||||||
stub_shared_folders do |config|
|
stub_shared_folders(<<-sf)
|
||||||
config.vm.share_folder("v-foo", "/foo", "/foo")
|
config.vm.share_folder("v-foo", "/foo", "/foo")
|
||||||
config.vm.share_folder("v-root", "/vagrant", ".", :disabled => true)
|
config.vm.share_folder("v-root", "/vagrant", ".", :disabled => true)
|
||||||
config.vm.share_folder("v-bar", "/bar", "/bar")
|
config.vm.share_folder("v-bar", "/bar", "/bar")
|
||||||
end
|
sf
|
||||||
|
|
||||||
assert_equal 2, @instance.shared_folders.length
|
assert_equal 2, @instance.shared_folders.length
|
||||||
assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort
|
assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not destroy original hash" do
|
should "not destroy original hash" do
|
||||||
@folders = stub_shared_folders do |config|
|
@folders = stub_shared_folders(<<-sf)
|
||||||
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
||||||
end
|
sf
|
||||||
|
|
||||||
folder = @folders["foo"].dup
|
folder = @folders["foo"].dup
|
||||||
|
|
||||||
|
@ -97,7 +88,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "setting up shared folder metadata" do
|
context "setting up shared folder metadata" do
|
||||||
setup do
|
setup do
|
||||||
stub_shared_folders
|
stub_shared_folders(<<-sf)
|
||||||
|
config.vm.share_folder("foo", "fooguest", "foohost")
|
||||||
|
config.vm.share_folder("bar", "barguest", "barhost")
|
||||||
|
sf
|
||||||
end
|
end
|
||||||
|
|
||||||
should "add all shared folders to the VM" do
|
should "add all shared folders to the VM" do
|
||||||
|
@ -119,7 +113,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "mounting the shared folders" do
|
context "mounting the shared folders" do
|
||||||
setup do
|
setup do
|
||||||
@folders = stub_shared_folders
|
@folders = stub_shared_folders(<<-sf)
|
||||||
|
config.vm.share_folder("foo", "fooguest", "foohost")
|
||||||
|
config.vm.share_folder("bar", "barguest", "barhost")
|
||||||
|
sf
|
||||||
@ssh = mock("ssh")
|
@ssh = mock("ssh")
|
||||||
@vm.ssh.stubs(:execute).yields(@ssh)
|
@vm.ssh.stubs(:execute).yields(@ssh)
|
||||||
@vm.system.stubs(:mount_shared_folder)
|
@vm.system.stubs(:mount_shared_folder)
|
||||||
|
|
Loading…
Reference in New Issue