From f06703cdb1ead62fd32e04899a3ee39a0ec33cb7 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 14 Dec 2014 23:28:14 -0500 Subject: [PATCH 1/3] Stub ATLAS_TOKEN in tests Without this stub, the tests will fail if ATLAS_TOKEN is set locally when running the tests. --- .../login/middleware/add_authentication_test.rb | 1 + test/unit/support/shared/base_context.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb index 57bb66558..99c99a8af 100644 --- a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb +++ b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb @@ -17,6 +17,7 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do before do allow(Vagrant).to receive(:server_url).and_return(server_url) + stub_env("ATLAS_TOKEN" => nil) end describe "#call" do diff --git a/test/unit/support/shared/base_context.rb b/test/unit/support/shared/base_context.rb index 35c26788a..0f823948d 100644 --- a/test/unit/support/shared/base_context.rb +++ b/test/unit/support/shared/base_context.rb @@ -83,6 +83,18 @@ shared_context "unit" do return Pathname.new(d) end + # Stub the given environment in ENV, without actually touching ENV. Keys and + # values are converted to strings because that's how the real ENV works. + def stub_env(hash) + allow(ENV).to receive(:[]).and_call_original + + hash.each do |key, value| + allow(ENV).to receive(:[]) + .with(key.to_s) + .and_return(value.to_s) + end + end + # This helper provides temporary environmental variable changes. def with_temp_env(environment) # Build up the new environment, preserving the old values so we From 214a79e057921509e2d4e2e191d7a7b1aa96bd92 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 14 Dec 2014 23:32:32 -0500 Subject: [PATCH 2/3] Pushes are hashed by name, not strategy. @mitchellh this is a partial revert of 84ae22e. It took me a little bit to figure out why this broke everything, but then I finally realized it. 84ae22e changes the finalize! function to lookup pushes by strategy type, but pushes are keyed by push strategy name. In other words, given: config.push.define("foo", strategy: "bar") the `push_configs` has will look like: { :foo => [:bar, #] } This is important, because if we key by strategy, the user cannot specify the same push strategy more than once: config.push.define("foo", strategy: "bar") config.push.define("zip", strategy: "bar") If we keyed off of the strategy, this would be impossible. --- plugins/kernel_v2/config/push.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/kernel_v2/config/push.rb b/plugins/kernel_v2/config/push.rb index e1cb95734..e0137b29d 100644 --- a/plugins/kernel_v2/config/push.rb +++ b/plugins/kernel_v2/config/push.rb @@ -21,18 +21,18 @@ module VagrantPlugins # Compile all the provider configurations @__defined_pushes.each do |name, tuples| - # Capture the strategy so we can use it later. This will be used in - # the block iteration for merging/overwriting - strategy = name - strategy = tuples[0][0] if tuples[0] - # Find the configuration class for this push - config_class = Vagrant.plugin("2").manager.push_configs[strategy] + config_class = Vagrant.plugin("2").manager.push_configs[name] config_class ||= Vagrant::Config::V2::DummyConfig # Load it up config = config_class.new + # Capture the strategy so we can use it later. This will be used in + # the block iteration for merging/overwriting + strategy = name + strategy = tuples[0][0] if tuples[0] + begin tuples.each do |s, b| # Update the strategy if it has changed, reseting the current From 0c7696f11e5ef1636f7d9ff174532c91b4173b2c Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 14 Dec 2014 23:36:32 -0500 Subject: [PATCH 3/3] Fix SafeExec tests --- .../plugins/pushes/local-exec/push_test.rb | 42 +------------------ 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/test/unit/plugins/pushes/local-exec/push_test.rb b/test/unit/plugins/pushes/local-exec/push_test.rb index 6896428d1..1efdfa3b1 100644 --- a/test/unit/plugins/pushes/local-exec/push_test.rb +++ b/test/unit/plugins/pushes/local-exec/push_test.rb @@ -93,47 +93,9 @@ describe VagrantPlugins::LocalExecPush::Push do end describe "#execute!" do - let(:exit_code) { 0 } - let(:stdout) { "This is the output" } - let(:stderr) { "This is the errput" } - - let(:process) do - double("process", - exit_code: exit_code, - stdout: stdout, - stderr: stderr, - ) - end - - before do - allow(Vagrant::Util::Subprocess).to receive(:execute) - .and_return(process) - end - - it "creates a subprocess" do - expect(Vagrant::Util::Subprocess).to receive(:execute) + it "safe execs" do + expect(Vagrant::Util::SafeExec).to receive(:exec) expect { subject.execute! }.to_not raise_error end - - it "returns the resulting process" do - expect(subject.execute!).to be(process) - end - - context "when the exit code is non-zero" do - let(:exit_code) { 1 } - - it "raises an exception" do - klass = VagrantPlugins::LocalExecPush::Errors::CommandFailed - cmd = ["foo", "bar"] - - expect { subject.execute!(*cmd) }.to raise_error(klass) { |error| - expect(error.message).to eq(I18n.t("local_exec_push.errors.command_failed", - cmd: cmd.join(" "), - stdout: stdout, - stderr: stderr, - )) - } - end - end end end