core: Box has a version field
This commit is contained in:
parent
87a85488d1
commit
d87c414327
|
@ -23,6 +23,11 @@ module Vagrant
|
||||||
# @return [Symbol]
|
# @return [Symbol]
|
||||||
attr_reader :provider
|
attr_reader :provider
|
||||||
|
|
||||||
|
# The version of this box.
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
attr_reader :version
|
||||||
|
|
||||||
# This is the directory on disk where this box exists.
|
# This is the directory on disk where this box exists.
|
||||||
#
|
#
|
||||||
# @return [Pathname]
|
# @return [Pathname]
|
||||||
|
@ -40,8 +45,9 @@ module Vagrant
|
||||||
# @param [Symbol] provider The provider that this box implements.
|
# @param [Symbol] provider The provider that this box implements.
|
||||||
# @param [Pathname] directory The directory where this box exists on
|
# @param [Pathname] directory The directory where this box exists on
|
||||||
# disk.
|
# disk.
|
||||||
def initialize(name, provider, directory)
|
def initialize(name, provider, version, directory)
|
||||||
@name = name
|
@name = name
|
||||||
|
@version = version
|
||||||
@provider = provider
|
@provider = provider
|
||||||
@directory = directory
|
@directory = directory
|
||||||
|
|
||||||
|
@ -96,7 +102,8 @@ module Vagrant
|
||||||
return super if !other.is_a?(self.class)
|
return super if !other.is_a?(self.class)
|
||||||
|
|
||||||
# Comparison is done by composing the name and provider
|
# Comparison is done by composing the name and provider
|
||||||
"#{@name}-#{@provider}" <=> "#{other.name}-#{other.provider}"
|
"#{@name}-#{@version}-#{@provider}" <=>
|
||||||
|
"#{other.name}-#{other.version}-#{other.provider}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -131,7 +131,7 @@ module Vagrant
|
||||||
with_temp_dir(temp_dir) do |final_temp_dir|
|
with_temp_dir(temp_dir) do |final_temp_dir|
|
||||||
# Get an instance of the box we just added before it is finalized
|
# Get an instance of the box we just added before it is finalized
|
||||||
# in the system so we can inspect and use its metadata.
|
# in the system so we can inspect and use its metadata.
|
||||||
box = Box.new(name, nil, final_temp_dir)
|
box = Box.new(name, nil, version, final_temp_dir)
|
||||||
|
|
||||||
# Get the provider, since we'll need that to at the least add it
|
# Get the provider, since we'll need that to at the least add it
|
||||||
# to the system or check that it matches what is given to us.
|
# to the system or check that it matches what is given to us.
|
||||||
|
@ -256,7 +256,7 @@ module Vagrant
|
||||||
provider_dir = versiondir.join(provider.to_s)
|
provider_dir = versiondir.join(provider.to_s)
|
||||||
next if !provider_dir.directory?
|
next if !provider_dir.directory?
|
||||||
@logger.info("Box found: #{name} (#{provider})")
|
@logger.info("Box found: #{name} (#{provider})")
|
||||||
return Box.new(name, provider, provider_dir)
|
return Box.new(name, provider, version, provider_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,21 +11,20 @@ describe Vagrant::Box do
|
||||||
|
|
||||||
let(:name) { "foo" }
|
let(:name) { "foo" }
|
||||||
let(:provider) { :virtualbox }
|
let(:provider) { :virtualbox }
|
||||||
|
let(:version) { "1.0" }
|
||||||
let(:directory) { environment.box2("foo", :virtualbox) }
|
let(:directory) { environment.box2("foo", :virtualbox) }
|
||||||
let(:instance) { described_class.new(name, provider, directory) }
|
subject { described_class.new(name, provider, version, directory) }
|
||||||
|
|
||||||
subject { described_class.new(name, provider, directory) }
|
|
||||||
|
|
||||||
it "provides the name" do
|
it "provides the name" do
|
||||||
instance.name.should == name
|
subject.name.should == name
|
||||||
end
|
end
|
||||||
|
|
||||||
it "provides the provider" do
|
it "provides the provider" do
|
||||||
instance.provider.should == provider
|
subject.provider.should == provider
|
||||||
end
|
end
|
||||||
|
|
||||||
it "provides the directory" do
|
it "provides the directory" do
|
||||||
instance.directory.should == directory
|
subject.directory.should == directory
|
||||||
end
|
end
|
||||||
|
|
||||||
it "provides the metadata associated with a box" do
|
it "provides the metadata associated with a box" do
|
||||||
|
@ -37,7 +36,7 @@ describe Vagrant::Box do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Verify the metadata
|
# Verify the metadata
|
||||||
instance.metadata.should == data
|
subject.metadata.should == data
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a corrupt metadata file" do
|
context "with a corrupt metadata file" do
|
||||||
|
@ -70,15 +69,15 @@ describe Vagrant::Box do
|
||||||
directory.exist?.should be
|
directory.exist?.should be
|
||||||
|
|
||||||
# Destroy it
|
# Destroy it
|
||||||
instance.destroy!.should be
|
subject.destroy!.should be
|
||||||
|
|
||||||
# Verify that it is "destroyed"
|
# Verify that it is "destroyed"
|
||||||
directory.exist?.should_not be
|
directory.exist?.should_not be
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not error destroying a non-existent box" do
|
it "should not error destroying a non-existent box" do
|
||||||
# Get the instance so that it is instantiated
|
# Get the subject so that it is instantiated
|
||||||
box = instance
|
box = subject
|
||||||
|
|
||||||
# Delete the directory
|
# Delete the directory
|
||||||
directory.rmtree
|
directory.rmtree
|
||||||
|
@ -100,36 +99,51 @@ describe Vagrant::Box do
|
||||||
|
|
||||||
# Repackage our box to some temporary directory
|
# Repackage our box to some temporary directory
|
||||||
box_output_path = temporary_dir.join("package.box")
|
box_output_path = temporary_dir.join("package.box")
|
||||||
instance.repackage(box_output_path).should be
|
expect(subject.repackage(box_output_path)).to be_true
|
||||||
|
|
||||||
# Let's now add this box again under a different name, and then
|
# Let's now add this box again under a different name, and then
|
||||||
# verify that we get the proper result back.
|
# verify that we get the proper result back.
|
||||||
new_box = box_collection.add(box_output_path, "foo2")
|
new_box = box_collection.add(box_output_path, "foo2", "1.0")
|
||||||
new_box.directory.join("test_file").read.should == test_file_contents
|
new_box.directory.join("test_file").read.should == test_file_contents
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "comparison and ordering" do
|
describe "comparison and ordering" do
|
||||||
it "should be equal if the name and provider match" do
|
it "should be equal if the name, provider, version match" do
|
||||||
a = described_class.new("a", :foo, directory)
|
a = described_class.new("a", :foo, "1.0", directory)
|
||||||
b = described_class.new("a", :foo, directory)
|
b = described_class.new("a", :foo, "1.0", directory)
|
||||||
|
|
||||||
a.should == b
|
a.should == b
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be equal if the name and provider do not match" do
|
it "should not be equal if name doesn't match" do
|
||||||
a = described_class.new("a", :foo, directory)
|
a = described_class.new("a", :foo, "1.0", directory)
|
||||||
b = described_class.new("b", :foo, directory)
|
b = described_class.new("b", :foo, "1.0", directory)
|
||||||
|
|
||||||
a.should_not == b
|
expect(a).to_not eq(b)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should sort them in order of name then provider" do
|
it "should not be equal if provider doesn't match" do
|
||||||
a = described_class.new("a", :foo, directory)
|
a = described_class.new("a", :foo, "1.0", directory)
|
||||||
b = described_class.new("b", :foo, directory)
|
b = described_class.new("a", :bar, "1.0", directory)
|
||||||
c = described_class.new("c", :foo2, directory)
|
|
||||||
|
|
||||||
[c, a, b].sort.should == [a, b, c]
|
expect(a).to_not eq(b)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be equal if version doesn't match" do
|
||||||
|
a = described_class.new("a", :foo, "1.0", directory)
|
||||||
|
b = described_class.new("a", :foo, "1.1", directory)
|
||||||
|
|
||||||
|
expect(a).to_not eq(b)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should sort them in order of name, version, provider" do
|
||||||
|
a = described_class.new("a", :foo, "1.0", directory)
|
||||||
|
b = described_class.new("a", :foo2, "1.0", directory)
|
||||||
|
c = described_class.new("a", :foo2, "1.1", directory)
|
||||||
|
d = described_class.new("b", :foo2, "1.0", directory)
|
||||||
|
|
||||||
|
[d, c, a, b].sort.should == [a, b, c, d]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue