(#8864) Improve `vagrant validate` command
Prior to this commit, the `vagrant validate` command would only validate the first machine in a vagrant file. This commit improves that by validating all known machines in the environment. If one is not found, it will properly throw an exception instead of a stacktrace.
This commit is contained in:
parent
c25944d7a9
commit
4bd95cbfe2
|
@ -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"))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue