Filter synced folders by allowed_synced_folder_types

This commit is contained in:
Max Lincoln 2014-12-16 23:35:01 -05:00
parent 3c6c496bb0
commit d781dce8f8
3 changed files with 25 additions and 3 deletions

View File

@ -25,6 +25,13 @@ module Vagrant
# Order the plugins by priority. Higher is tried before lower.
ordered = ordered.sort { |a, b| b[0] <=> a[0] }
allowed_types = machine.config.vm.allowed_synced_folder_types
if allowed_types
ordered = ordered.select do |_, key, impl|
allowed_types.include? key
end
end
# Find the proper implementation
ordered.each do |_, key, impl|
return key if impl.new.usable?(machine)

View File

@ -14,6 +14,7 @@ module VagrantPlugins
class VMConfig < Vagrant.plugin("2", :config)
DEFAULT_VM_NAME = :default
attr_accessor :allowed_synced_folder_types
attr_accessor :base_mac
attr_accessor :boot_timeout
attr_accessor :box
@ -36,6 +37,7 @@ module VagrantPlugins
attr_reader :provisioners
def initialize
@allowed_synced_folder_types = UNSET_VALUE
@base_mac = UNSET_VALUE
@boot_timeout = UNSET_VALUE
@box = UNSET_VALUE
@ -347,6 +349,7 @@ module VagrantPlugins
def finalize!
# Defaults
@allowed_synced_folder_types = nil if @allowed_synced_folder_types == UNSET_VALUE
@base_mac = nil if @base_mac == UNSET_VALUE
@boot_timeout = 300 if @boot_timeout == UNSET_VALUE
@box = nil if @box == UNSET_VALUE

View File

@ -28,14 +28,26 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
end
end
let(:vm_config) { double("machine_vm_config") }
let(:vm_config) { double("machine_vm_config", :allowed_synced_folder_types => nil) }
describe "default_synced_folder_type" do
it "returns the usable implementation" do
plugins = {
"bad" => [impl(false, "bad"), 0],
"nope" => [impl(true, "nope"), 1],
"good" => [impl(true, "good"), 5],
"good" => [impl(true, "good"), 1],
"best" => [impl(true, "best"), 5],
}
result = subject.default_synced_folder_type(machine, plugins)
expect(result).to eq("best")
end
it "filters based on allowed_synced_folder_types" do
expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["bad", "good"])
plugins = {
"bad" => [impl(false, "bad"), 0],
"good" => [impl(true, "good"), 1],
"best" => [impl(true, "best"), 5],
}
result = subject.default_synced_folder_type(machine, plugins)