core: more intuitive logic around default providers
This commit is contained in:
parent
ba6272cc48
commit
ab9f91568e
|
@ -249,16 +249,20 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# This returns the provider name for the default provider for this
|
# This returns the provider name for the default provider for this
|
||||||
# environment. The provider returned is currently hardcoded to "virtualbox"
|
|
||||||
# but one day should be a detected valid, best-case provider for this
|
|
||||||
# environment.
|
# environment.
|
||||||
#
|
#
|
||||||
# @return [Symbol] Name of the default provider.
|
# @return [Symbol] Name of the default provider.
|
||||||
def default_provider(**opts)
|
def default_provider(**opts)
|
||||||
|
opts[:force_default] = true if !opts.has_key?(:force_default)
|
||||||
|
|
||||||
default = ENV["VAGRANT_DEFAULT_PROVIDER"]
|
default = ENV["VAGRANT_DEFAULT_PROVIDER"]
|
||||||
default = nil if default == ""
|
default = nil if default == ""
|
||||||
default = default.to_sym if default
|
default = default.to_sym if default
|
||||||
|
|
||||||
|
# If we're forcing the default, just short-circuit and return
|
||||||
|
# that (the default behavior)
|
||||||
|
return default if default && opts[:force_default]
|
||||||
|
|
||||||
ordered = []
|
ordered = []
|
||||||
Vagrant.plugin("2").manager.providers.each do |key, data|
|
Vagrant.plugin("2").manager.providers.each do |key, data|
|
||||||
impl = data[0]
|
impl = data[0]
|
||||||
|
|
|
@ -717,7 +717,7 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is the default provider if it is usable" do
|
it "is the default provider set if usable" do
|
||||||
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
|
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
|
||||||
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
|
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
|
||||||
plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }]
|
plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }]
|
||||||
|
@ -728,6 +728,26 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is the default provider set even if unusable" do
|
||||||
|
plugin_providers[:baz] = [provider_usable_class(false), { priority: 5 }]
|
||||||
|
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
|
||||||
|
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
|
||||||
|
|
||||||
|
with_temp_env("VAGRANT_DEFAULT_PROVIDER" => "baz") do
|
||||||
|
expect(subject.default_provider).to eq(:baz)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is the usable despite default if not forced" do
|
||||||
|
plugin_providers[:baz] = [provider_usable_class(false), { priority: 5 }]
|
||||||
|
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
|
||||||
|
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
|
||||||
|
|
||||||
|
with_temp_env("VAGRANT_DEFAULT_PROVIDER" => "baz") do
|
||||||
|
expect(subject.default_provider(force_default: false)).to eq(:bar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "is VirtualBox if nothing else is usable" do
|
it "is VirtualBox if nothing else is usable" do
|
||||||
plugin_providers[:foo] = [provider_usable_class(false), { priority: 5 }]
|
plugin_providers[:foo] = [provider_usable_class(false), { priority: 5 }]
|
||||||
plugin_providers[:bar] = [provider_usable_class(false), { priority: 5 }]
|
plugin_providers[:bar] = [provider_usable_class(false), { priority: 5 }]
|
||||||
|
|
Loading…
Reference in New Issue