/cc @sethvargo - Some weirdness here but overall should work fine. I'm not sure if there was a GH issue this should be attached to or close. To explain: We just use the first machine with the default provider. A Vagrant::Environment guarantees there is at least one machine, so `env.machine_names.first` will always work. And we can just use the default provider because we don't really care. Finally, it can be any old machine we pass in because we just want the "global" config to validate and there is no way to say "don't validate machine-specific configs", so we might as well just pick the first machine to validate.
133 lines
3.6 KiB
Ruby
133 lines
3.6 KiB
Ruby
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"
|
|
|
|
let(:iso_env) { isolated_environment }
|
|
let(:env) do
|
|
iso_env.vagrantfile(<<-VF)
|
|
Vagrant.configure("2") do |config|
|
|
config.vm.box = "nope"
|
|
end
|
|
VF
|
|
iso_env.create_vagrant_env
|
|
end
|
|
|
|
let(:argv) { [] }
|
|
let(:pushes) { {} }
|
|
|
|
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!)
|
|
.and_return(:noop)
|
|
allow(env).to receive(:pushes)
|
|
allow(env).to receive(:push)
|
|
end
|
|
|
|
it "validates the pushes" do
|
|
expect(subject).to receive(:validate_pushes!).once
|
|
subject.execute
|
|
end
|
|
|
|
it "validates the configuration" do
|
|
iso_env.vagrantfile("")
|
|
|
|
subject = described_class.new(argv, iso_env.create_vagrant_env)
|
|
allow(subject).to receive(:validate_pushes!)
|
|
.and_return(:noop)
|
|
|
|
expect { subject.execute }.to raise_error(
|
|
Vagrant::Errors::ConfigInvalid)
|
|
end
|
|
|
|
it "delegates to Environment#push" do
|
|
expect(env).to receive(:push).once
|
|
subject.execute
|
|
end
|
|
end
|
|
|
|
describe "#validate_pushes!" do
|
|
context "when there are no pushes defined" do
|
|
let(:pushes) { [] }
|
|
|
|
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") }
|
|
let(:pushes) { [:noop] }
|
|
|
|
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
|
|
it "returns that push" do
|
|
expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when no strategy is given" do
|
|
it "returns the strategy" do
|
|
expect(subject.validate_pushes!(pushes)).to eq(:noop)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when there are multiple pushes defined" do
|
|
let(:noop) { double("noop") }
|
|
let(:ftp) { double("ftp") }
|
|
let(:pushes) { [:noop, :ftp] }
|
|
|
|
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
|
|
it "returns the strategy" do
|
|
expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
|
|
expect(subject.validate_pushes!(pushes, :ftp)).to eq(:ftp)
|
|
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
|