2014-10-23 17:51:18 +00:00
|
|
|
require File.expand_path("../../../../base", __FILE__)
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/commands/push/command")
|
|
|
|
|
|
|
|
describe VagrantPlugins::CommandPush::Command do
|
|
|
|
include_context "unit"
|
|
|
|
include_context "command plugin helpers"
|
|
|
|
|
2015-01-07 20:51:20 +00:00
|
|
|
let(:iso_env) { isolated_environment }
|
2014-10-23 17:51:18 +00:00
|
|
|
let(:env) do
|
2015-01-07 20:51:20 +00:00
|
|
|
iso_env.vagrantfile(<<-VF)
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.box = "hashicorp/precise64"
|
|
|
|
end
|
|
|
|
VF
|
|
|
|
iso_env.create_vagrant_env
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:argv) { [] }
|
2014-10-23 20:01:43 +00:00
|
|
|
let(:pushes) { {} }
|
2014-10-23 17:51:18 +00:00
|
|
|
|
|
|
|
subject { described_class.new(argv, env) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Vagrant.plugin("2").manager.stub(pushes: pushes)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:validate_pushes!)
|
2014-12-02 18:45:45 +00:00
|
|
|
.and_return(:noop)
|
2014-10-23 17:51:18 +00:00
|
|
|
allow(env).to receive(:pushes)
|
|
|
|
allow(env).to receive(:push)
|
|
|
|
end
|
|
|
|
|
2017-02-24 14:23:14 +00:00
|
|
|
# NOTE: Disabled due to deprecation
|
|
|
|
#
|
|
|
|
# it "validates the pushes" do
|
|
|
|
# expect(subject).to receive(:validate_pushes!).once
|
|
|
|
# subject.execute
|
|
|
|
# end
|
2014-10-23 17:51:18 +00:00
|
|
|
|
2017-02-24 14:23:14 +00:00
|
|
|
# it "delegates to Environment#push" do
|
|
|
|
# expect(env).to receive(:push).once
|
|
|
|
# subject.execute
|
|
|
|
# end
|
2015-01-07 20:51:20 +00:00
|
|
|
|
2017-02-24 14:23:14 +00:00
|
|
|
# it "validates the configuration" do
|
|
|
|
# iso_env.vagrantfile <<-EOH
|
|
|
|
# Vagrant.configure("2") do |config|
|
|
|
|
# config.vm.box = "hashicorp/precise64"
|
2015-01-07 20:51:20 +00:00
|
|
|
|
2017-02-24 14:23:14 +00:00
|
|
|
# config.push.define "noop" do |push|
|
|
|
|
# push.bad = "ham"
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# EOH
|
2015-01-07 20:51:20 +00:00
|
|
|
|
2017-02-24 14:23:14 +00:00
|
|
|
# subject = described_class.new(argv, iso_env.create_vagrant_env)
|
|
|
|
# allow(subject).to receive(:validate_pushes!)
|
|
|
|
# .and_return(:noop)
|
2015-01-07 20:51:20 +00:00
|
|
|
|
2017-02-24 14:23:14 +00:00
|
|
|
# expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err|
|
|
|
|
# expect(err.message).to include("The following settings shouldn't exist: bad")
|
|
|
|
# }
|
|
|
|
# end
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#validate_pushes!" do
|
|
|
|
context "when there are no pushes defined" do
|
2014-12-02 06:20:27 +00:00
|
|
|
let(:pushes) { [] }
|
2014-10-23 17:51:18 +00:00
|
|
|
|
|
|
|
context "when a strategy is given" do
|
|
|
|
it "raises an exception" do
|
|
|
|
expect { subject.validate_pushes!(pushes, :noop) }
|
|
|
|
.to raise_error(Vagrant::Errors::PushesNotDefined)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no strategy is given" do
|
|
|
|
it "raises an exception" do
|
|
|
|
expect { subject.validate_pushes!(pushes) }
|
|
|
|
.to raise_error(Vagrant::Errors::PushesNotDefined)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there is one push defined" do
|
|
|
|
let(:noop) { double("noop") }
|
2014-12-02 06:20:27 +00:00
|
|
|
let(:pushes) { [:noop] }
|
2014-10-23 17:51:18 +00:00
|
|
|
|
|
|
|
context "when a strategy is given" do
|
|
|
|
context "when that strategy is not defined" do
|
|
|
|
it "raises an exception" do
|
|
|
|
expect { subject.validate_pushes!(pushes, :bacon) }
|
|
|
|
.to raise_error(Vagrant::Errors::PushStrategyNotDefined)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when that strategy is defined" do
|
2014-12-02 18:30:16 +00:00
|
|
|
it "returns that push" do
|
2014-12-02 18:44:42 +00:00
|
|
|
expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no strategy is given" do
|
2014-12-02 18:45:14 +00:00
|
|
|
it "returns the strategy" do
|
2014-12-02 18:44:42 +00:00
|
|
|
expect(subject.validate_pushes!(pushes)).to eq(:noop)
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there are multiple pushes defined" do
|
|
|
|
let(:noop) { double("noop") }
|
|
|
|
let(:ftp) { double("ftp") }
|
2014-12-02 06:20:27 +00:00
|
|
|
let(:pushes) { [:noop, :ftp] }
|
2014-10-23 17:51:18 +00:00
|
|
|
|
|
|
|
context "when a strategy is given" do
|
|
|
|
context "when that strategy is not defined" do
|
|
|
|
it "raises an exception" do
|
|
|
|
expect { subject.validate_pushes!(pushes, :bacon) }
|
|
|
|
.to raise_error(Vagrant::Errors::PushStrategyNotDefined)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when that strategy is defined" do
|
2014-12-02 18:30:16 +00:00
|
|
|
it "returns the strategy" do
|
2014-12-02 18:44:42 +00:00
|
|
|
expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
|
|
|
|
expect(subject.validate_pushes!(pushes, :ftp)).to eq(:ftp)
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no strategy is given" do
|
|
|
|
it "raises an exception" do
|
|
|
|
expect { subject.validate_pushes!(pushes) }
|
|
|
|
.to raise_error(Vagrant::Errors::PushStrategyNotProvided)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|