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"
|
|
|
|
|
|
|
|
it "has no boxes by default" do
|
2011-11-03 04:42:09 +00:00
|
|
|
result = execute("vagrant", "box", "list")
|
2011-11-09 07:03:15 +00:00
|
|
|
result.stdout.should match_output(:no_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
|
2011-11-13 21:49:21 +00:00
|
|
|
result = execute("vagrant", "box", "add", "foo", box_path("default"))
|
2011-12-23 05:46:43 +00:00
|
|
|
result.should succeed
|
2011-11-04 04:38:15 +00:00
|
|
|
|
|
|
|
# Verify that the box now shows up in the list of available boxes
|
2011-11-09 07:03:15 +00:00
|
|
|
result = execute("vagrant", "box", "list")
|
|
|
|
result.stdout.should match_output(:box_installed, "foo")
|
2011-11-04 04:38:15 +00:00
|
|
|
end
|
2011-11-04 04:55:53 +00:00
|
|
|
|
2012-01-11 02:45:38 +00:00
|
|
|
it "errors if attempting to add a box with the same name" do
|
|
|
|
require_box("default")
|
|
|
|
|
|
|
|
# Add the box, which we expect to succeed
|
|
|
|
assert_execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
|
|
|
|
|
|
# Adding it again should not succeed
|
|
|
|
result = execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
|
|
result.should_not succeed
|
|
|
|
result.stderr.should match_output(:box_already_exists, "foo")
|
|
|
|
end
|
|
|
|
|
2012-01-11 04:37:33 +00:00
|
|
|
it "overwrites a box when adding with `--force`" do
|
|
|
|
require_box("default")
|
|
|
|
|
|
|
|
# Add the box, which we expect to succeed
|
|
|
|
assert_execute("vagrant", "box", "add", "foo", box_path("default"))
|
|
|
|
|
|
|
|
# Adding it again should not succeed
|
|
|
|
assert_execute("vagrant", "box", "add", "foo", box_path("default"), "--force")
|
|
|
|
end
|
|
|
|
|
2011-11-07 07:47:23 +00:00
|
|
|
it "gives an error if the file doesn't exist" do
|
2011-11-09 07:03:15 +00:00
|
|
|
result = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box")
|
2011-12-23 05:46:43 +00:00
|
|
|
result.should_not succeed
|
2011-12-10 21:35:03 +00:00
|
|
|
result.stderr.should match_output(:box_path_doesnt_exist)
|
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
|
|
|
|
|
2011-11-09 07:03:15 +00:00
|
|
|
result = execute("vagrant", "box", "add", "foo", invalid.to_s)
|
2011-12-23 05:46:43 +00:00
|
|
|
result.should_not succeed
|
2011-12-10 21:35:03 +00:00
|
|
|
result.stderr.should match_output(:box_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.
|
2011-11-13 21:49:21 +00:00
|
|
|
execute("vagrant", "box", "add", "foo", box_path("default"))
|
2011-11-04 06:05:06 +00:00
|
|
|
execute("vagrant", "box", "remove", "foo")
|
2011-11-09 07:03:15 +00:00
|
|
|
result = execute("vagrant", "box", "list")
|
2011-12-23 05:46:43 +00:00
|
|
|
result.should succeed
|
2011-11-09 07:03:15 +00:00
|
|
|
result.stdout.should match_output(:no_boxes)
|
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")
|
|
|
|
|
2011-11-13 21:49:21 +00:00
|
|
|
original_size = File.size(box_path("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.
|
2011-11-13 21:49:21 +00:00
|
|
|
execute("vagrant", "box", "add", "foo", box_path("default"))
|
2011-11-04 06:05:06 +00:00
|
|
|
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-09 07:03:15 +00:00
|
|
|
repackaged_file.file?.should be, "package.box should exist in cwd of environment"
|
2011-11-04 06:05:06 +00:00
|
|
|
|
|
|
|
# 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
|
2011-11-09 07:09:04 +00:00
|
|
|
size_diff.should be < 1000, "Sizes should be very similar"
|
2011-11-04 06:05:06 +00:00
|
|
|
end
|
2011-11-03 04:42:09 +00:00
|
|
|
end
|