core: more intuitive logic around default providers

This commit is contained in:
Mitchell Hashimoto 2014-05-01 09:46:40 -07:00
parent ba6272cc48
commit ab9f91568e
2 changed files with 27 additions and 3 deletions

View File

@ -249,16 +249,20 @@ module Vagrant
end
# 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.
#
# @return [Symbol] Name of the default provider.
def default_provider(**opts)
opts[:force_default] = true if !opts.has_key?(:force_default)
default = ENV["VAGRANT_DEFAULT_PROVIDER"]
default = nil 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 = []
Vagrant.plugin("2").manager.providers.each do |key, data|
impl = data[0]

View File

@ -717,7 +717,7 @@ VF
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[:bar] = [provider_usable_class(true), { priority: 7 }]
plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }]
@ -728,6 +728,26 @@ VF
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
plugin_providers[:foo] = [provider_usable_class(false), { priority: 5 }]
plugin_providers[:bar] = [provider_usable_class(false), { priority: 5 }]