1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
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 = "hashicorp/precise64"
config.vm.synced_folder ".", "/vagrant", disabled: true
end
VF
iso_env.create_vagrant_env
end
let(:argv) { [] }
let(:pushes) { {} }
subject { described_class.new(argv, env) }
before do
allow(Vagrant.plugin("2").manager).to receive(:pushes).and_return(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 "delegates to Environment#push" do
expect(env).to receive(:push).once
subject.execute
end
it "validates the configuration" do
iso_env.vagrantfile <<-EOH
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.push.define "noop" do |push|
push.bad = "ham"
end
end
EOH
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) { |err|
expect(err.message).to include("The following settings shouldn't exist: bad")
}
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
|