2011-11-03 04:42:09 +00:00
|
|
|
require File.expand_path("../base", __FILE__)
|
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
describe "vagrant box" do
|
|
|
|
include_context "acceptance"
|
|
|
|
|
2011-11-04 06:05:06 +00:00
|
|
|
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
|
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "has no boxes by default" do
|
2011-11-03 04:42:09 +00:00
|
|
|
result = execute("vagrant", "box", "list")
|
2011-11-05 21:59:17 +00:00
|
|
|
assert(output(result.stdout).no_boxes,
|
|
|
|
"output should say there are no installed boxes")
|
2011-11-03 04:42:09 +00:00
|
|
|
end
|
2011-11-04 04:38:15 +00:00
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "can add a box from a file" do
|
2011-11-04 06:05:06 +00:00
|
|
|
require_box("default")
|
2011-11-04 04:38:15 +00:00
|
|
|
|
|
|
|
# Add the box, which we expect to succeed
|
|
|
|
results = execute("vagrant", "box", "add", "foo", config.boxes["default"])
|
|
|
|
assert(results.success?, "Box add should succeed.")
|
|
|
|
|
|
|
|
# Verify that the box now shows up in the list of available boxes
|
|
|
|
results = execute("vagrant", "box", "list")
|
2011-11-05 21:59:17 +00:00
|
|
|
assert(output(results.stdout).box_installed("foo"),
|
|
|
|
"foo box should exist after it is added")
|
2011-11-04 04:38:15 +00:00
|
|
|
end
|
2011-11-04 04:55:53 +00:00
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "gives an error if the file doesn't exist" do
|
2011-11-04 04:55:53 +00:00
|
|
|
results = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box")
|
|
|
|
assert(!results.success?, "Box add should fail.")
|
2011-11-05 21:59:17 +00:00
|
|
|
assert(output(results.stdout).box_path_doesnt_exist,
|
|
|
|
"Should show an error message about the file not existing.")
|
2011-11-04 04:55:53 +00:00
|
|
|
end
|
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "gives an error if the file is not a valid box" do
|
|
|
|
invalid = environment.workdir.join("nope.txt")
|
2011-11-04 05:22:19 +00:00
|
|
|
invalid.open("w+") do |f|
|
|
|
|
f.write("INVALID!")
|
|
|
|
end
|
|
|
|
|
|
|
|
results = execute("vagrant", "box", "add", "foo", invalid.to_s)
|
|
|
|
assert(!results.success?, "Box add should fail.")
|
2011-11-05 21:59:17 +00:00
|
|
|
assert(output(results.stdout).box_invalid,
|
|
|
|
"should say the box is invalid")
|
2011-11-04 05:22:19 +00:00
|
|
|
end
|
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "can add a box from an HTTP server" do
|
|
|
|
pending("Need to setup HTTP server functionality")
|
2011-11-04 04:55:53 +00:00
|
|
|
end
|
2011-11-04 06:05:06 +00:00
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "can remove a box" do
|
2011-11-04 06:05:06 +00:00
|
|
|
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")
|
2011-11-05 21:59:17 +00:00
|
|
|
assert(output(results.stdout).no_boxes,
|
|
|
|
"No boxes should be installed")
|
2011-11-04 06:05:06 +00:00
|
|
|
end
|
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "can repackage a box" do
|
2011-11-04 06:05:06 +00:00
|
|
|
require_box("default")
|
|
|
|
|
|
|
|
original_size = File.size(config.boxes["default"])
|
2011-11-07 07:47:23 +00:00
|
|
|
logger.debug("Original package size: #{original_size}")
|
2011-11-04 06:05:06 +00:00
|
|
|
|
|
|
|
# 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
|
2011-11-07 07:47:23 +00:00
|
|
|
repackaged_file = environment.workdir.join("package.box")
|
2011-11-04 06:05:06 +00:00
|
|
|
assert(repackaged_file.file?, "package.box should exist in cwd of environment")
|
|
|
|
|
|
|
|
# Compare the sizes
|
|
|
|
repackaged_size = repackaged_file.size
|
2011-11-07 07:47:23 +00:00
|
|
|
logger.debug("Repackaged size: #{repackaged_size}")
|
2011-11-04 06:05:06 +00:00
|
|
|
size_diff = (repackaged_size - original_size).abs
|
|
|
|
assert(size_diff < 1000, "Sizes should be very similar")
|
|
|
|
end
|
2011-11-03 04:42:09 +00:00
|
|
|
end
|