Box2 reads the metadata.json file.
This commit is contained in:
parent
cd6c60775c
commit
2eaa850853
|
@ -1,3 +1,5 @@
|
||||||
|
require "json"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
# Represents a "box," which is a package Vagrant environment that is used
|
# Represents a "box," which is a package Vagrant environment that is used
|
||||||
# as a base image when creating a new guest machine.
|
# as a base image when creating a new guest machine.
|
||||||
|
@ -22,6 +24,12 @@ module Vagrant
|
||||||
# @return [Pathname]
|
# @return [Pathname]
|
||||||
attr_reader :directory
|
attr_reader :directory
|
||||||
|
|
||||||
|
# This is the metadata for the box. This is read from the "metadata.json"
|
||||||
|
# file that all boxes require.
|
||||||
|
#
|
||||||
|
# @return [Hash]
|
||||||
|
attr_reader :metadata
|
||||||
|
|
||||||
# This is used to initialize a box.
|
# This is used to initialize a box.
|
||||||
#
|
#
|
||||||
# @param [String] name Logical name of the box.
|
# @param [String] name Logical name of the box.
|
||||||
|
@ -32,6 +40,7 @@ module Vagrant
|
||||||
@name = name
|
@name = name
|
||||||
@provider = provider
|
@provider = provider
|
||||||
@directory = directory
|
@directory = directory
|
||||||
|
@metadata = JSON.parse(directory.join("metadata.json").read)
|
||||||
end
|
end
|
||||||
|
|
||||||
# This deletes the box. This is NOT undoable.
|
# This deletes the box. This is NOT undoable.
|
||||||
|
|
|
@ -63,7 +63,7 @@ module Unit
|
||||||
# Create a metadata.json file
|
# Create a metadata.json file
|
||||||
box_metadata_file = box_dir.join("metadata.json")
|
box_metadata_file = box_dir.join("metadata.json")
|
||||||
box_metadata_file.open("w") do |f|
|
box_metadata_file.open("w") do |f|
|
||||||
f.write("")
|
f.write("{}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the box directory
|
# Return the box directory
|
||||||
|
|
|
@ -5,9 +5,11 @@ require "pathname"
|
||||||
describe Vagrant::Box2 do
|
describe Vagrant::Box2 do
|
||||||
include_context "unit"
|
include_context "unit"
|
||||||
|
|
||||||
|
let(:environment) { isolated_environment }
|
||||||
|
|
||||||
let(:name) { "foo" }
|
let(:name) { "foo" }
|
||||||
let(:provider) { :virtualbox }
|
let(:provider) { :virtualbox }
|
||||||
let(:directory) { temporary_dir }
|
let(:directory) { environment.box2("foo", :virtualbox) }
|
||||||
let(:instance) { described_class.new(name, provider, directory) }
|
let(:instance) { described_class.new(name, provider, directory) }
|
||||||
|
|
||||||
it "provides the name" do
|
it "provides the name" do
|
||||||
|
@ -22,6 +24,18 @@ describe Vagrant::Box2 do
|
||||||
instance.directory.should == directory
|
instance.directory.should == directory
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "provides the metadata associated with a box" do
|
||||||
|
data = { "foo" => "bar" }
|
||||||
|
|
||||||
|
# Write the metadata
|
||||||
|
directory.join("metadata.json").open("w") do |f|
|
||||||
|
f.write(JSON.generate(data))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Verify the metadata
|
||||||
|
instance.metadata.should == data
|
||||||
|
end
|
||||||
|
|
||||||
describe "destroying" do
|
describe "destroying" do
|
||||||
it "should destroy an existing box" do
|
it "should destroy an existing box" do
|
||||||
# Verify that our "box" exists
|
# Verify that our "box" exists
|
||||||
|
@ -35,11 +49,14 @@ describe Vagrant::Box2 do
|
||||||
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
|
||||||
|
box = instance
|
||||||
|
|
||||||
# Delete the directory
|
# Delete the directory
|
||||||
directory.rmtree
|
directory.rmtree
|
||||||
|
|
||||||
# Destroy it
|
# Destroy it
|
||||||
instance.destroy!.should be
|
box.destroy!.should be
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue