Merge branch 'filter_synced_folders' of https://github.com/maxlinc/vagrant into maxlinc-filter_synced_folders
This commit is contained in:
commit
cea44847de
|
@ -25,6 +25,15 @@ 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 = allowed_types.map do |type|
|
||||
ordered.find do |_, key, impl|
|
||||
key == type
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
# Find the proper implementation
|
||||
ordered.each do |_, key, impl|
|
||||
return key if impl.new.usable?(machine)
|
||||
|
|
|
@ -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
|
||||
|
@ -39,6 +40,7 @@ module VagrantPlugins
|
|||
def initialize
|
||||
@logger = Log4r::Logger.new("vagrant::config::vm")
|
||||
|
||||
@allowed_synced_folder_types = UNSET_VALUE
|
||||
@base_mac = UNSET_VALUE
|
||||
@boot_timeout = UNSET_VALUE
|
||||
@box = UNSET_VALUE
|
||||
|
@ -351,6 +353,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
|
||||
|
@ -375,6 +378,10 @@ module VagrantPlugins
|
|||
@usable_port_range = (2200..2250)
|
||||
end
|
||||
|
||||
if @allowed_synced_folder_types
|
||||
@allowed_synced_folder_types = Array(@allowed_synced_folder_types).map(&:to_sym)
|
||||
end
|
||||
|
||||
# Make sure that the download checksum is a string and that
|
||||
# the type is a symbol
|
||||
@box_download_checksum = "" if !@box_download_checksum
|
||||
|
|
|
@ -28,19 +28,47 @@ 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)
|
||||
expect(result).to eq("good")
|
||||
end
|
||||
|
||||
it "reprioritizes based on allowed_synced_folder_types" do
|
||||
plugins = {
|
||||
"bad" => [impl(false, "bad"), 0],
|
||||
"good" => [impl(true, "good"), 1],
|
||||
"same" => [impl(true, "same"), 1],
|
||||
}
|
||||
|
||||
expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["good", "same"])
|
||||
result = subject.default_synced_folder_type(machine, plugins)
|
||||
expect(result).to eq("good")
|
||||
|
||||
expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["same", "good"])
|
||||
result = subject.default_synced_folder_type(machine, plugins)
|
||||
expect(result).to eq("same")
|
||||
end
|
||||
end
|
||||
|
||||
describe "impl_opts" do
|
||||
|
|
Loading…
Reference in New Issue