Merge pull request #8889 from briancain/8864/master/improve-config-validate-cmd

Improve `vagrant validate` command
This commit is contained in:
Brian Cain 2017-08-15 14:56:15 -07:00 committed by GitHub
commit 567f26a7be
2 changed files with 50 additions and 4 deletions

View File

@ -16,10 +16,10 @@ module VagrantPlugins
argv = parse_options(opts)
return if !argv
# Validate the configuration
@env.machine(@env.machine_names.first, @env.default_provider).action_raw(
:config_validate,
Vagrant::Action::Builtin::ConfigValidate)
# Validate the configuration of all machines
with_target_vms() do |machine|
machine.action_raw(:config_validate, Vagrant::Action::Builtin::ConfigValidate)
end
@env.ui.info(I18n.t("vagrant.commands.validate.success"))

View File

@ -48,5 +48,51 @@ describe VagrantPlugins::CommandValidate::Command do
expect(err.message).to include("The following settings shouldn't exist: bix")
}
end
it "validates correct Vagrantfile of all vms" do
iso_env.vagrantfile <<-EOH
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
EOH
expect(env.ui).to receive(:info).with(any_args) { |message, _|
expect(message).to include("Vagrantfile validated successfully.")
}
expect(subject.execute).to eq(0)
end
it "validates the configuration of all vms" do
iso_env.vagrantfile <<-EOH
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
EOH
expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err|
expect(err.message).to include("The following settings shouldn't exist: not_provider")
}
end
it "throws an exception if there's no Vagrantfile" do
expect { subject.execute }.to raise_error(Vagrant::Errors::NoEnvironmentError)
end
end
end