core: BoxAdd errors if name doesn't match metadata
This commit is contained in:
parent
b23ad41c40
commit
38248c240c
|
@ -97,6 +97,12 @@ module Vagrant
|
|||
metadata_path.delete if metadata_path && metadata_path.file?
|
||||
end
|
||||
|
||||
if env[:box_name] && metadata.name != env[:box_name]
|
||||
raise Errors::BoxAddNameMismatch,
|
||||
actual_name: metadata.name,
|
||||
requested_name: env[:box_name]
|
||||
end
|
||||
|
||||
metadata_version = metadata.version(
|
||||
version || ">= 0", provider: provider)
|
||||
if !metadata_version
|
||||
|
|
|
@ -120,6 +120,10 @@ module Vagrant
|
|||
error_key(:batch_multi_error)
|
||||
end
|
||||
|
||||
class BoxAddNameMismatch < VagrantError
|
||||
error_key(:box_add_name_mismatch)
|
||||
end
|
||||
|
||||
class BoxAddNameRequired < VagrantError
|
||||
error_key(:box_add_name_required)
|
||||
end
|
||||
|
|
|
@ -289,6 +289,15 @@ en:
|
|||
Name: %{name}
|
||||
Provider: %{provider}
|
||||
Version: %{version}
|
||||
box_add_name_mismatch: |-
|
||||
The box you're adding has a name different from the name you
|
||||
requested. For boxes with metadata, you cannot override the name.
|
||||
If you're adding a box using `vagrant box add`, don't specify
|
||||
the `--name` parameter. If the box is being added via a Vagrantfile,
|
||||
change the `config.vm.box` value to match the name below.
|
||||
|
||||
Requested name: %{requested_name}
|
||||
Actual name: %{actual_name}
|
||||
box_add_name_required: |-
|
||||
A name is required when adding a box file directly. Please pass
|
||||
the `--name` parameter to `vagrant box add`. See
|
||||
|
|
|
@ -558,6 +558,41 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
|||
subject.call(env)
|
||||
end
|
||||
|
||||
it "raises an exception if the name doesn't match a requested name" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
"versions": [
|
||||
{
|
||||
"version": "0.5"
|
||||
},
|
||||
{
|
||||
"version": "0.7",
|
||||
"providers": [
|
||||
{
|
||||
"name": "virtualbox",
|
||||
"url": "#{box_path}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
RAW
|
||||
f.close
|
||||
end
|
||||
|
||||
env[:box_name] = "foo"
|
||||
env[:box_url] = tf.path
|
||||
|
||||
box_collection.should_receive(:add).never
|
||||
app.should_receive(:call).never
|
||||
|
||||
expect { subject.call(env) }.
|
||||
to raise_error(Vagrant::Errors::BoxAddNameMismatch)
|
||||
end
|
||||
|
||||
it "raises an exception if no matching version" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
|
|
Loading…
Reference in New Issue