Find boxes with new on-disk structure.
The box collection can now find new-style boxes with providers and return proper Box objects. In the future, we'll also have to implement upgrading old style ones as well.
This commit is contained in:
parent
42826356ad
commit
a6d7bd48fd
|
@ -65,6 +65,7 @@ module Vagrant
|
||||||
autoload :Box, 'vagrant/box'
|
autoload :Box, 'vagrant/box'
|
||||||
autoload :Box2, 'vagrant/box2'
|
autoload :Box2, 'vagrant/box2'
|
||||||
autoload :BoxCollection, 'vagrant/box_collection'
|
autoload :BoxCollection, 'vagrant/box_collection'
|
||||||
|
autoload :BoxCollection2, 'vagrant/box_collection2'
|
||||||
autoload :CLI, 'vagrant/cli'
|
autoload :CLI, 'vagrant/cli'
|
||||||
autoload :Command, 'vagrant/command'
|
autoload :Command, 'vagrant/command'
|
||||||
autoload :Communication, 'vagrant/communication'
|
autoload :Communication, 'vagrant/communication'
|
||||||
|
|
|
@ -20,6 +20,12 @@ module Vagrant
|
||||||
# @Param [String] provider Provider that the box implements.
|
# @Param [String] provider Provider that the box implements.
|
||||||
# @return [Box] The box found, or `nil` if not found.
|
# @return [Box] The box found, or `nil` if not found.
|
||||||
def find(name, provider)
|
def find(name, provider)
|
||||||
|
# First look directly for the box we're asking for.
|
||||||
|
box_directory = @directory.join(name, provider.to_s, "metadata.json")
|
||||||
|
return Box2.new(name, provider, box_directory.dirname) if box_directory.file?
|
||||||
|
|
||||||
|
# Didn't find it, return nil
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,26 @@ module Unit
|
||||||
box_dir
|
box_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Creates a fake box to exist in this environment.
|
||||||
|
#
|
||||||
|
# @param [String] name Name of the box
|
||||||
|
# @param [Symbol] provider Provider the box was built for.
|
||||||
|
# @return [Pathname] Path to the box directory.
|
||||||
|
def box2(name, provider)
|
||||||
|
# Make the box directory
|
||||||
|
box_dir = boxes_dir.join(name, provider.to_s)
|
||||||
|
box_dir.mkpath
|
||||||
|
|
||||||
|
# Create a metadata.json file
|
||||||
|
box_metadata_file = box_dir.join("metadata.json")
|
||||||
|
box_metadata_file.open("w") do |f|
|
||||||
|
f.write("")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return the box directory
|
||||||
|
box_dir
|
||||||
|
end
|
||||||
|
|
||||||
def boxes_dir
|
def boxes_dir
|
||||||
dir = @homedir.join("boxes")
|
dir = @homedir.join("boxes")
|
||||||
dir.mkpath
|
dir.mkpath
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
require File.expand_path("../../base", __FILE__)
|
||||||
|
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
|
describe Vagrant::BoxCollection2 do
|
||||||
|
include_context "unit"
|
||||||
|
|
||||||
|
let(:box_class) { Vagrant::Box2 }
|
||||||
|
let(:environment) { isolated_environment }
|
||||||
|
let(:instance) { described_class.new(environment.boxes_dir) }
|
||||||
|
|
||||||
|
describe "finding" do
|
||||||
|
it "should return nil if the box does not exist" do
|
||||||
|
instance.find("foo", :i_dont_exist).should be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return a box if the box does exist" do
|
||||||
|
# Create the "box"
|
||||||
|
environment.box2("foo", :virtualbox)
|
||||||
|
|
||||||
|
# Actual test
|
||||||
|
result = instance.find("foo", :virtualbox)
|
||||||
|
result.should_not be_nil
|
||||||
|
result.should be_kind_of(box_class)
|
||||||
|
result.name.should == "foo"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue