Adding a box that already exists should result in an exception.
This commit is contained in:
parent
9cb0015b6e
commit
9e33d16ca1
|
@ -23,6 +23,9 @@ module Vagrant
|
|||
# This adds a new box to the system.
|
||||
#
|
||||
# There are some exceptional cases:
|
||||
# * BoxAlreadyExists - The box you're attempting to add already exists.
|
||||
# * BoxProviderDoesntMatch - If the given box provider doesn't match the
|
||||
# actual box provider in the untarred box.
|
||||
#
|
||||
# Preconditions:
|
||||
# * File given in `path` must exist.
|
||||
|
@ -33,9 +36,14 @@ module Vagrant
|
|||
# will be verified with the `metadata.json` file in the box and is
|
||||
# meant as a basic check.
|
||||
def add(path, name, provider)
|
||||
@logger.debug("Adding box: #{name} (#{provider}) from #{path}")
|
||||
if find(name, provider)
|
||||
@logger.error("Box already exists, can't add: #{name} #{provider}")
|
||||
raise Errors::BoxAlreadyExists, :name => name, :provider => provider
|
||||
end
|
||||
|
||||
box_dir = @directory.join(name, provider.to_s)
|
||||
@logger.debug("Adding box: #{path}")
|
||||
@logger.debug("Box directory: #{box_dir}")
|
||||
@logger.debug("New box directory: #{box_dir}")
|
||||
|
||||
# Create the directory that'll store our box
|
||||
box_dir.mkpath
|
||||
|
|
|
@ -24,6 +24,19 @@ describe Vagrant::BoxCollection2 do
|
|||
box.should_not be_nil
|
||||
end
|
||||
|
||||
it "should raise an exception if the box already exists" do
|
||||
prev_box_name = "foo"
|
||||
prev_box_provider = :virtualbox
|
||||
|
||||
# Create the box we're adding
|
||||
environment.box2(prev_box_name, prev_box_provider)
|
||||
|
||||
# Attempt to add the box with the same name
|
||||
box_path = environment.box2_file(prev_box_provider)
|
||||
expect { instance.add(box_path, prev_box_name, prev_box_provider) }.
|
||||
to raise_error(Vagrant::Errors::BoxAlreadyExists)
|
||||
end
|
||||
|
||||
it "should raise an exception and not add the box if the provider doesn't match" do
|
||||
box_name = "foo"
|
||||
good_provider = :virtualbox
|
||||
|
|
Loading…
Reference in New Issue