Add validation error for empty box
This commit adds a unique error message for an empty box value. It requires modifications to vagrantfile.rb because some Vagrantfile config is used before validation occurs.
This commit is contained in:
parent
352b955d09
commit
eecf1dbe57
@ -197,7 +197,7 @@ module Vagrant
|
||||
local_keys = keys.dup
|
||||
|
||||
# Load the box Vagrantfile, if there is one
|
||||
if config.vm.box && boxes
|
||||
if !config.vm.box.to_s.empty? && boxes
|
||||
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
||||
if box
|
||||
box_vagrantfile = find_vagrantfile(box.directory)
|
||||
|
||||
@ -511,7 +511,7 @@ module VagrantPlugins
|
||||
@base_mac = nil if @base_mac == UNSET_VALUE
|
||||
@base_address = nil if @base_address == UNSET_VALUE
|
||||
@boot_timeout = 300 if @boot_timeout == UNSET_VALUE
|
||||
@box = nil if @box == UNSET_VALUE || @box.to_s.empty?
|
||||
@box = nil if @box == UNSET_VALUE
|
||||
@ignore_box_vagrantfile = false if @ignore_box_vagrantfile == UNSET_VALUE
|
||||
|
||||
if @box_check_update == UNSET_VALUE
|
||||
@ -732,6 +732,10 @@ module VagrantPlugins
|
||||
errors << I18n.t("vagrant.config.vm.clone_and_box")
|
||||
end
|
||||
|
||||
if box && box.empty?
|
||||
errors << I18n.t("vagrant.config.vm.box_empty")
|
||||
end
|
||||
|
||||
errors << I18n.t("vagrant.config.vm.hostname_invalid_characters", name: machine.name) if \
|
||||
@hostname && @hostname !~ /^[a-z0-9][-.a-z0-9]*$/i
|
||||
|
||||
|
||||
@ -1980,6 +1980,7 @@ en:
|
||||
Checksum type specified but "box_download_checksum" is blank
|
||||
box_download_checksum_notblank: |-
|
||||
Checksum specified but must also specify "box_download_checksum_type"
|
||||
box_empty: "Box value is an empty string."
|
||||
box_missing: "A box must be specified."
|
||||
box_download_options_type: |-
|
||||
Found "box_download_options" specified as type '%{type}', should be a Hash
|
||||
|
||||
@ -368,6 +368,17 @@ describe Vagrant::Vagrantfile do
|
||||
to raise_error(Vagrant::Errors::ProviderNotUsable)
|
||||
end
|
||||
|
||||
it "does not try to load the box if the box is empty" do
|
||||
provider_cls = register_provider("foo")
|
||||
|
||||
configure do |config|
|
||||
config.vm.box = ""
|
||||
end
|
||||
|
||||
expect(boxes).not_to receive(:find)
|
||||
results = subject.machine_config(:default, :foo, boxes)
|
||||
end
|
||||
|
||||
context "when provider validation is ignored" do
|
||||
before do
|
||||
configure do |config|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user