2013-11-22 01:38:17 +00:00
|
|
|
require "vagrant"
|
|
|
|
require Vagrant.source_root.join("test/unit/base")
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
require Vagrant.source_root.join("plugins/providers/virtualbox/config")
|
2013-11-22 01:38:17 +00:00
|
|
|
require Vagrant.source_root.join("plugins/providers/virtualbox/synced_folder")
|
|
|
|
|
|
|
|
describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
|
2018-01-08 22:57:31 +00:00
|
|
|
include_context "unit"
|
2013-11-22 01:38:17 +00:00
|
|
|
let(:machine) do
|
|
|
|
double("machine").tap do |m|
|
2017-08-04 17:10:58 +00:00
|
|
|
allow(m).to receive(:provider_config).and_return(VagrantPlugins::ProviderVirtualBox::Config.new)
|
|
|
|
allow(m).to receive(:provider_name).and_return(:virtualbox)
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
before do
|
|
|
|
machine.provider_config.finalize!
|
|
|
|
end
|
|
|
|
|
2013-11-22 01:38:17 +00:00
|
|
|
describe "usable" do
|
|
|
|
it "should be with virtualbox provider" do
|
2017-08-04 17:10:58 +00:00
|
|
|
allow(machine).to receive(:provider_name).and_return(:virtualbox)
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(subject).to be_usable(machine)
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be with another provider" do
|
2017-08-04 17:10:58 +00:00
|
|
|
allow(machine).to receive(:provider_name).and_return(:vmware_fusion)
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(subject).not_to be_usable(machine)
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
2014-04-11 01:26:19 +00:00
|
|
|
|
|
|
|
it "should not be usable if not functional vboxsf" do
|
|
|
|
machine.provider_config.functional_vboxsf = false
|
|
|
|
expect(subject).to_not be_usable(machine)
|
|
|
|
end
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "prepare" do
|
|
|
|
let(:driver) { double("driver") }
|
2018-01-08 22:57:31 +00:00
|
|
|
let(:provider) { double("driver", driver: driver) }
|
|
|
|
let(:folders) { {"/folder"=>
|
|
|
|
{:SharedFoldersEnableSymlinksCreate=>true,
|
|
|
|
:guestpath=>"/folder",
|
|
|
|
:hostpath=>"/Users/brian/vagrant-folder",
|
|
|
|
:disabled=>false,
|
|
|
|
:__vagrantfile=>true}} }
|
|
|
|
|
|
|
|
let(:folders_disabled) { {"/folder"=>
|
|
|
|
{:SharedFoldersEnableSymlinksCreate=>false,
|
|
|
|
:guestpath=>"/folder",
|
|
|
|
:hostpath=>"/Users/brian/vagrant-folder",
|
|
|
|
:disabled=>false,
|
|
|
|
:__vagrantfile=>true}} }
|
|
|
|
|
|
|
|
let(:folders_nosymvar) { {"/folder"=>
|
|
|
|
{:guestpath=>"/folder",
|
|
|
|
:hostpath=>"/Users/brian/vagrant-folder",
|
|
|
|
:disabled=>false,
|
|
|
|
:__vagrantfile=>true}} }
|
2013-11-22 01:38:17 +00:00
|
|
|
|
|
|
|
before do
|
2018-01-08 22:57:31 +00:00
|
|
|
allow(machine).to receive(:provider).and_return(provider)
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
|
|
|
|
2018-01-08 22:57:31 +00:00
|
|
|
it "should prepare and share the folders" do
|
|
|
|
expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}])
|
|
|
|
subject.prepare(machine, folders, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prepare and share the folders without symlinks enabled" do
|
|
|
|
expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>false}])
|
|
|
|
subject.prepare(machine, folders_disabled, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prepare and share the folders without symlinks enabled with env var set" do
|
|
|
|
stub_env('VAGRANT_DISABLE_VBOXSYMLINKCREATE'=>'1')
|
|
|
|
|
|
|
|
expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>false}])
|
|
|
|
subject.prepare(machine, folders_nosymvar, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prepare and share the folders and override symlink setting" do
|
|
|
|
stub_env('VAGRANT_DISABLE_VBOXSYMLINKCREATE'=>'1')
|
|
|
|
|
|
|
|
expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}])
|
|
|
|
subject.prepare(machine, folders, nil)
|
|
|
|
end
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|
2017-09-25 19:14:56 +00:00
|
|
|
|
|
|
|
describe "os_friendly_id" do
|
|
|
|
it "should not replace normal chars" do
|
|
|
|
expect(subject.send(:os_friendly_id, 'perfectly_valid0_name')).to eq('perfectly_valid0_name')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should replace spaces" do
|
|
|
|
expect(subject.send(:os_friendly_id, 'Program Files')).to eq('Program_Files')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should replace leading underscore" do
|
|
|
|
expect(subject.send(:os_friendly_id, '_vagrant')).to eq('vagrant')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should replace slash" do
|
|
|
|
expect(subject.send(:os_friendly_id, 'va/grant')).to eq('va_grant')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should replace leading underscore and slash" do
|
|
|
|
expect(subject.send(:os_friendly_id, '/vagrant')).to eq('vagrant')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should replace backslash" do
|
|
|
|
expect(subject.send(:os_friendly_id, 'foo\\bar')).to eq('foo_bar')
|
|
|
|
end
|
|
|
|
end
|
2013-11-22 01:38:17 +00:00
|
|
|
end
|