SharedFolder action converted to new Environment
This commit is contained in:
parent
e1c4f91664
commit
d384408782
|
@ -3,7 +3,7 @@ module Vagrant
|
|||
module VM
|
||||
class SharedFolders < Base
|
||||
def shared_folders
|
||||
Vagrant.config.vm.shared_folders.inject([]) do |acc, data|
|
||||
@runner.env.config.vm.shared_folders.inject([]) do |acc, data|
|
||||
name, value = data
|
||||
acc << [name, File.expand_path(value[:hostpath]), value[:guestpath]]
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ module Vagrant
|
|||
def after_boot
|
||||
logger.info "Mounting shared folders..."
|
||||
|
||||
Vagrant::SSH.execute do |ssh|
|
||||
@runner.env.ssh.execute do |ssh|
|
||||
shared_folders.each do |name, hostpath, guestpath|
|
||||
logger.info "-- #{name}: #{guestpath}"
|
||||
ssh.exec!("sudo mkdir -p #{guestpath}")
|
||||
|
@ -57,8 +57,8 @@ module Vagrant
|
|||
|
||||
# Determine the permission string to attach to the mount command
|
||||
perms = []
|
||||
perms << "uid=#{Vagrant.config.vm.shared_folder_uid}"
|
||||
perms << "gid=#{Vagrant.config.vm.shared_folder_gid}"
|
||||
perms << "uid=#{@runner.env.config.vm.shared_folder_uid}"
|
||||
perms << "gid=#{@runner.env.config.vm.shared_folder_gid}"
|
||||
perms = " -o #{perms.join(",")}" if !perms.empty?
|
||||
|
||||
attempts = 0
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
|
||||
class SharedFoldersActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
|
||||
mock_config
|
||||
end
|
||||
|
||||
|
@ -27,11 +27,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "convert the vagrant config values into an array" do
|
||||
mock_config do |config|
|
||||
env = mock_environment do |config|
|
||||
config.vm.shared_folders.clear
|
||||
config.vm.share_folder("foo", "bar", "baz")
|
||||
end
|
||||
|
||||
@runner.expects(:env).returns(env)
|
||||
|
||||
result = [["foo", "baz", "bar"]]
|
||||
assert_equal result, @action.shared_folders
|
||||
end
|
||||
|
@ -39,11 +41,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
should "expand the path of the host folder" do
|
||||
File.expects(:expand_path).with("baz").once.returns("expanded_baz")
|
||||
|
||||
mock_config do |config|
|
||||
env = mock_environment do |config|
|
||||
config.vm.shared_folders.clear
|
||||
config.vm.share_folder("foo", "bar", "baz")
|
||||
end
|
||||
|
||||
@runner.expects(:env).returns(env)
|
||||
|
||||
result = [["foo", "expanded_baz", "bar"]]
|
||||
assert_equal result, @action.shared_folders
|
||||
end
|
||||
|
@ -62,7 +66,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
sf.expects(:destroy).once.in_sequence(destroy_seq)
|
||||
end
|
||||
|
||||
@mock_vm.expects(:reload!).once.in_sequence(destroy_seq)
|
||||
@runner.expects(:reload!).once.in_sequence(destroy_seq)
|
||||
@action.clear_shared_folders
|
||||
end
|
||||
end
|
||||
|
@ -95,9 +99,9 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
@folders.each do |name, hostpath, guestpath|
|
||||
ssh.expects(:exec!).with("sudo mkdir -p #{guestpath}").in_sequence(mount_seq)
|
||||
@action.expects(:mount_folder).with(ssh, name, guestpath).in_sequence(mount_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{Vagrant.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{@runner.env.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
|
||||
end
|
||||
Vagrant::SSH.expects(:execute).yields(ssh)
|
||||
@runner.env.ssh.expects(:execute).yields(ssh)
|
||||
|
||||
@action.after_boot
|
||||
end
|
||||
|
@ -119,7 +123,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "execute the proper mount command" do
|
||||
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{Vagrant.config.ssh.username},gid=#{Vagrant.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
|
||||
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@runner.env.config.ssh.username},gid=#{@runner.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
|
||||
mount_folder
|
||||
end
|
||||
|
||||
|
@ -158,11 +162,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
should "add uid AND gid to mount" do
|
||||
uid = "foo"
|
||||
gid = "bar"
|
||||
mock_config do |config|
|
||||
env = mock_environment do |config|
|
||||
config.vm.shared_folder_uid = uid
|
||||
config.vm.shared_folder_gid = gid
|
||||
end
|
||||
|
||||
@runner.expects(:env).twice.returns(env)
|
||||
|
||||
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
|
||||
mount_folder
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue