2017-02-07 06:59:20 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
require_relative "../../../../../plugins/commands/validate/command"
|
|
|
|
|
|
|
|
describe VagrantPlugins::CommandValidate::Command do
|
|
|
|
include_context "unit"
|
|
|
|
include_context "command plugin helpers"
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
let(:vagrantfile_content){ "" }
|
2017-02-07 06:59:20 +00:00
|
|
|
let(:iso_env) do
|
2018-10-30 19:35:46 +00:00
|
|
|
env = isolated_environment
|
|
|
|
env.vagrantfile(vagrantfile_content)
|
|
|
|
env.create_vagrant_env
|
2017-02-07 06:59:20 +00:00
|
|
|
end
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
let(:action_runner) { double("action_runner") }
|
|
|
|
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
2017-02-07 06:59:20 +00:00
|
|
|
|
|
|
|
let(:argv) { [] }
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
I18n.load_path << Vagrant.source_root.join("plugins/commands/port/locales/en.yml")
|
|
|
|
I18n.reload!
|
|
|
|
end
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
subject { described_class.new(argv, iso_env) }
|
2017-02-07 06:59:20 +00:00
|
|
|
|
|
|
|
describe "#execute" do
|
2018-10-30 19:35:46 +00:00
|
|
|
context "validating configs" do
|
|
|
|
let(:vagrantfile_content) do
|
|
|
|
<<-VF
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.box = "hashicorp/precise64"
|
|
|
|
end
|
|
|
|
VF
|
|
|
|
end
|
|
|
|
it "validates correct Vagrantfile" do
|
|
|
|
expect(machine).to receive(:action_raw) do |name, action, env|
|
|
|
|
expect(name).to eq(:config_validate)
|
|
|
|
expect(action).to eq(Vagrant::Action::Builtin::ConfigValidate)
|
|
|
|
expect(env).to eq({})
|
2017-02-07 06:59:20 +00:00
|
|
|
end
|
2018-10-30 19:35:46 +00:00
|
|
|
expect(iso_env.ui).to receive(:info).with(any_args) { |message, _|
|
|
|
|
expect(message).to include("Vagrantfile validated successfully.")
|
|
|
|
}
|
2017-02-07 06:59:20 +00:00
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
expect(subject.execute).to eq(0)
|
|
|
|
end
|
2017-02-07 06:59:20 +00:00
|
|
|
end
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
context "invalid configs" do
|
|
|
|
let(:vagrantfile_content) do
|
|
|
|
<<-VF
|
2017-02-07 06:59:20 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.bix = "hashicorp/precise64"
|
|
|
|
end
|
2018-10-30 19:35:46 +00:00
|
|
|
VF
|
|
|
|
end
|
|
|
|
it "validates the configuration" do
|
|
|
|
expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err|
|
|
|
|
expect(err.message).to include("The following settings shouldn't exist: bix")
|
|
|
|
}
|
|
|
|
end
|
2017-02-07 06:59:20 +00:00
|
|
|
end
|
2017-08-15 20:52:35 +00:00
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
context "valid configs for multiple vms" do
|
|
|
|
let(:vagrantfile_content) do
|
|
|
|
<<-VF
|
2017-08-15 20:52:35 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.box = "hashicorp/precise64"
|
|
|
|
|
|
|
|
config.vm.define "test" do |vm|
|
|
|
|
vm.vm.provider :virtualbox
|
|
|
|
end
|
|
|
|
|
|
|
|
config.vm.define "machine" do |vm|
|
|
|
|
vm.vm.provider :virtualbox
|
|
|
|
end
|
|
|
|
end
|
2018-10-30 19:35:46 +00:00
|
|
|
VF
|
|
|
|
end
|
|
|
|
it "validates correct Vagrantfile of all vms" do
|
|
|
|
expect(machine).to receive(:action_raw) do |name, action, env|
|
|
|
|
expect(name).to eq(:config_validate)
|
|
|
|
expect(action).to eq(Vagrant::Action::Builtin::ConfigValidate)
|
|
|
|
expect(env).to eq({})
|
|
|
|
end
|
|
|
|
expect(iso_env.ui).to receive(:info).with(any_args) { |message, _|
|
|
|
|
expect(message).to include("Vagrantfile validated successfully.")
|
|
|
|
}
|
2017-08-15 20:52:35 +00:00
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
expect(subject.execute).to eq(0)
|
|
|
|
end
|
2017-08-15 20:52:35 +00:00
|
|
|
end
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
context "an invalid config for some vms" do
|
|
|
|
let(:vagrantfile_content) do
|
|
|
|
<<-VF
|
2017-08-15 20:52:35 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.box = "hashicorp/precise64"
|
|
|
|
|
|
|
|
config.vm.define "test" do |vm|
|
|
|
|
vm.vm.provider :virtualbox
|
|
|
|
end
|
|
|
|
|
|
|
|
config.vm.define "machine" do |vm|
|
|
|
|
vm.vm.not_provider :virtualbox
|
|
|
|
end
|
|
|
|
end
|
2018-10-30 19:35:46 +00:00
|
|
|
VF
|
|
|
|
end
|
|
|
|
it "validates the configuration of all vms" do
|
|
|
|
expect(machine).to receive(:action_raw) do |name, action, env|
|
|
|
|
expect(name).to eq(:config_validate)
|
|
|
|
expect(action).to eq(Vagrant::Action::Builtin::ConfigValidate)
|
|
|
|
expect(env).to eq({})
|
|
|
|
end
|
|
|
|
|
|
|
|
expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err|
|
|
|
|
expect(err.message).to include("The following settings shouldn't exist: not_provider")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with the ignore provider flag" do
|
|
|
|
let(:argv) { ["--ignore-provider"]}
|
|
|
|
let(:vagrantfile_content) do
|
|
|
|
<<-VF
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.box = "hashicorp/precise64"
|
|
|
|
|
|
|
|
config.vm.define "test" do |vm|
|
|
|
|
vm.vm.hostname = "test"
|
|
|
|
vm.vm.provider :virtualbox do |v|
|
|
|
|
v.not_a_real_option = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
VF
|
|
|
|
end
|
|
|
|
it "ignores provider specific configurations with the flag" do
|
2018-12-03 22:45:26 +00:00
|
|
|
allow(subject).to receive(:mockup_providers!).and_return("")
|
|
|
|
allow(FileUtils).to receive(:remove_entry).and_return(true)
|
2018-10-30 19:35:46 +00:00
|
|
|
expect(iso_env.ui).to receive(:info).with(any_args) { |message, _|
|
|
|
|
expect(message).to include("Vagrantfile validated successfully.")
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(machine).to receive(:action_raw) do |name, action, env|
|
|
|
|
expect(name).to eq(:config_validate)
|
|
|
|
expect(action).to eq(Vagrant::Action::Builtin::ConfigValidate)
|
|
|
|
expect(env).to eq({:ignore_provider=>true})
|
|
|
|
end
|
2017-08-15 20:52:35 +00:00
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
expect(subject.execute).to eq(0)
|
|
|
|
end
|
2017-08-15 20:52:35 +00:00
|
|
|
end
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
context "no vagrantfile" do
|
|
|
|
let(:vagrantfile_content){ "" }
|
|
|
|
let(:env) { isolated_environment.create_vagrant_env }
|
|
|
|
subject { described_class.new(argv, env) }
|
|
|
|
it "throws an exception if there's no Vagrantfile" do
|
|
|
|
expect { subject.execute }.to raise_error(Vagrant::Errors::NoEnvironmentError)
|
|
|
|
end
|
2017-08-15 20:52:35 +00:00
|
|
|
end
|
2017-02-07 06:59:20 +00:00
|
|
|
end
|
|
|
|
end
|