From 7c4252e24a8c475efafef9fb7a24acd887b7d75c Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 21 Mar 2017 10:44:02 -0700 Subject: [PATCH] Prevent other provider install attempts when explicit provider given --- plugins/commands/up/command.rb | 2 +- test/unit/plugins/commands/up/command_test.rb | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/unit/plugins/commands/up/command_test.rb diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index df9d2f5f7..d26dd4cb5 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -128,7 +128,7 @@ module VagrantPlugins # First create a set of all the providers we need to check for. # Most likely this will be a set of one. 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 entry = @env.machine_index.get(machine.name.to_s) diff --git a/test/unit/plugins/commands/up/command_test.rb b/test/unit/plugins/commands/up/command_test.rb new file mode 100644 index 000000000..5a260764b --- /dev/null +++ b/test/unit/plugins/commands/up/command_test.rb @@ -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