Prevent other provider install attempts when explicit provider given

This commit is contained in:
Chris Roberts 2017-03-21 10:44:02 -07:00
parent e0b9a6fabd
commit 7c4252e24a
2 changed files with 66 additions and 1 deletions

View File

@ -128,7 +128,7 @@ module VagrantPlugins
# First create a set of all the providers we need to check for. # First create a set of all the providers we need to check for.
# Most likely this will be a set of one. # Most likely this will be a set of one.
providers = Set.new providers = Set.new
with_target_vms(names) do |machine| with_target_vms(names, provider: provider) do |machine|
# Check if we have this machine in the index # Check if we have this machine in the index
entry = @env.machine_index.get(machine.name.to_s) entry = @env.machine_index.get(machine.name.to_s)

View File

@ -0,0 +1,65 @@
require File.expand_path("../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/commands/up/command")
describe VagrantPlugins::CommandUp::Command do
include_context "unit"
let(:argv) { [] }
let(:vagrantfile_content){ "" }
let(:iso_env) do
env = isolated_environment
env.vagrantfile(vagrantfile_content)
env.create_vagrant_env
end
subject { described_class.new(argv, iso_env) }
let(:action_runner) { double("action_runner") }
before do
iso_env.stub(action_runner: action_runner)
end
context "with no argument" do
let(:vagrantfile_content){ "Vagrant.configure(2){|config| config.vm.box = 'dummy'}" }
it "should bring up the default box" do
batch = double("environment_batch")
expect(iso_env).to receive(:batch).and_yield(batch)
expect(batch).to receive(:action).with(anything, :up, anything)
subject.execute
end
context "with VAGRANT_DEFAULT_PROVIDER set" do
before do
if ENV["VAGRANT_DEFAULT_PROVIDER"]
@original_default = ENV["VAGRANT_DEFAULT_PROVIDER"]
end
ENV["VAGRANT_DEFAULT_PROVIDER"] = "unknown"
end
after do
if @original_default
ENV["VAGRANT_DEFAULT_PROVIDER"] = @original_default
else
ENV.delete("VAGRANT_DEFAULT_PROVIDER")
end
end
it "should attempt to use dummy provider" do
expect{ subject.execute }.to raise_error
end
context "with --provider set" do
let(:argv){ ["--provider", "dummy"] }
it "should only use provider explicitly set" do
batch = double("environment_batch")
expect(iso_env).to receive(:batch).and_yield(batch)
expect(batch).to receive(:action).with(anything, :up, anything)
subject.execute
end
end
end
end
end