Tests for removing and repackaging a box

This commit is contained in:
Mitchell Hashimoto 2011-11-03 23:05:06 -07:00
parent d9d8029783
commit 9a551837d6
1 changed files with 42 additions and 3 deletions

View File

@ -1,15 +1,21 @@
require "digest/sha1"
require File.expand_path("../base", __FILE__) require File.expand_path("../base", __FILE__)
class BoxTest < AcceptanceTest class BoxTest < AcceptanceTest
def require_box(name)
if !config.boxes.has_key?(name) || !File.file?(config.boxes[name])
raise ArgumentError, "The configuration should specify a '#{name}' box."
end
end
should "have no boxes by default" do should "have no boxes by default" do
result = execute("vagrant", "box", "list") result = execute("vagrant", "box", "list")
assert result.stdout.read =~ /There are no installed boxes!/ assert result.stdout.read =~ /There are no installed boxes!/
end end
should "add a box from a file" do should "add a box from a file" do
if !config.boxes.has_key?("default") || !File.file?(config.boxes["default"]) require_box("default")
raise ArgumentError, "The configuration should specify a 'default' box."
end
# Add the box, which we expect to succeed # Add the box, which we expect to succeed
results = execute("vagrant", "box", "add", "foo", config.boxes["default"]) results = execute("vagrant", "box", "add", "foo", config.boxes["default"])
@ -43,4 +49,37 @@ class BoxTest < AcceptanceTest
# TODO: Spin up an HTTP server to serve a file, add and test. # TODO: Spin up an HTTP server to serve a file, add and test.
skip("Need to setup HTTP server functionality") skip("Need to setup HTTP server functionality")
end end
should "remove a box" do
require_box("default")
# Add the box, remove the box, then verify that the box no longer
# shows up in the list of available boxes.
execute("vagrant", "box", "add", "foo", config.boxes["default"])
execute("vagrant", "box", "remove", "foo")
results = execute("vagrant", "box", "list")
assert(results.success?, "box list should succeed")
assert(results.stdout.read =~ /^There are no installed boxes!/,
"box list should be empty")
end
should "repackage a box" do
require_box("default")
original_size = File.size(config.boxes["default"])
# Add the box, repackage it, and verify that a package.box is
# dumped of relatively similar size.
execute("vagrant", "box", "add", "foo", config.boxes["default"])
execute("vagrant", "box", "repackage", "foo")
# By default, repackage should dump into package.box into the CWD
repackaged_file = @environment.workdir.join("package.box")
assert(repackaged_file.file?, "package.box should exist in cwd of environment")
# Compare the sizes
repackaged_size = repackaged_file.size
size_diff = (repackaged_size - original_size).abs
assert(size_diff < 1000, "Sizes should be very similar")
end
end end