Skip to content

Commit

Permalink
Acceptance tests now take a "box_directory" instead of paths to indiv…
Browse files Browse the repository at this point in the history
…idual boxes
  • Loading branch information
mitchellh committed Nov 13, 2011
1 parent bb06a20 commit a8909cb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
14 changes: 9 additions & 5 deletions tasks/acceptance.rake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ namespace :acceptance do
end

desc "Generates the configuration for acceptance tests from current source."
task :config do
require File.expand_path("../lib/vagrant/version", __FILE__)
require File.expand_path('../test/acceptance/support/tempdir', __FILE__)
task :config, :box_dir do |t, args|
require File.expand_path("../../lib/vagrant/version", __FILE__)
require File.expand_path('../../test/acceptance/support/tempdir', __FILE__)

# Get the directory for the boxes
box_dir = Pathname.new(args[:directory] || File.expand_path("../../test/tmp/boxes", __FILE__))

# Generate the binstubs for the Vagrant binary
tempdir = Tempdir.new
Expand All @@ -80,8 +83,9 @@ namespace :acceptance do
"vagrant_path" => File.join(tempdir.path, "vagrant"),
"vagrant_version" => Vagrant::VERSION,
"env" => {
"BUNDLE_GEMFILE" => File.expand_path("../Gemfile", __FILE__)
}
"BUNDLE_GEMFILE" => File.expand_path("../../Gemfile", __FILE__)
},
"box_directory" => box_dir.to_s
}

File.open("acceptance_config.yml", "w+") do |f|
Expand Down
14 changes: 4 additions & 10 deletions test/acceptance/box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
describe "vagrant box" do
include_context "acceptance"

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

it "has no boxes by default" do
result = execute("vagrant", "box", "list")
result.stdout.should match_output(:no_boxes)
Expand All @@ -18,7 +12,7 @@ def require_box(name)
require_box("default")

# Add the box, which we expect to succeed
result = execute("vagrant", "box", "add", "foo", config.boxes["default"])
result = execute("vagrant", "box", "add", "foo", box_path("default"))
result.should be_success

# Verify that the box now shows up in the list of available boxes
Expand Down Expand Up @@ -52,7 +46,7 @@ def require_box(name)

# 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", "add", "foo", box_path("default"))
execute("vagrant", "box", "remove", "foo")
result = execute("vagrant", "box", "list")
result.should be_success
Expand All @@ -62,12 +56,12 @@ def require_box(name)
it "can repackage a box" do
require_box("default")

original_size = File.size(config.boxes["default"])
original_size = File.size(box_path("default"))
logger.debug("Original package size: #{original_size}")

# 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", "add", "foo", box_path("default"))
execute("vagrant", "box", "repackage", "foo")

# By default, repackage should dump into package.box into the CWD
Expand Down
8 changes: 6 additions & 2 deletions test/acceptance/ssh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
it_behaves_like "a command that requires a virtual machine", ["vagrant", "ssh"]

it "is able to SSH into a running virtual machine" do
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
require_box("default")

assert_execute("vagrant", "box", "add", "base", box_path("default"))
assert_execute("vagrant", "init")
assert_execute("vagrant", "up")

Expand All @@ -24,7 +26,9 @@
end

it "is able to execute a single command via the command line" do
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
require_box("default")

assert_execute("vagrant", "box", "add", "base", box_path("default"))
assert_execute("vagrant", "init")
assert_execute("vagrant", "up")

Expand Down
10 changes: 4 additions & 6 deletions test/acceptance/support/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config
attr_reader :vagrant_path
attr_reader :vagrant_version
attr_reader :env
attr_reader :boxes
attr_reader :box_directory

def initialize(path)
@logger = Log4r::Logger.new("acceptance::config")
Expand All @@ -19,7 +19,7 @@ def initialize(path)
@vagrant_path = options["vagrant_path"]
@vagrant_version = options["vagrant_version"]
@env = options["env"]
@boxes = options["boxes"]
@box_directory = options["box_directory"]

# Verify the configuration object.
validate
Expand All @@ -34,10 +34,8 @@ def validate
raise ArgumentError, "'vagrant_path' must point to the `vagrant` executable"
elsif !@vagrant_version
raise ArgumentError, "`vagrant_version' must be set to the version of the `vagrant` executable"
end

if !@boxes || !@boxes.is_a?(Hash)
raise ArgumentError, "`boxes` must be a dictionary of available boxes on the local filesystem."
elsif !@box_directory || !File.directory?(@box_directory)
raise ArgumentError, "`box_directory` must be set to a folder containing boxes for the tests."
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/acceptance/support/shared/base_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ def assert_execute(*args, &block)
assert(result.success?, "expected '#{args.join(" ")}' to succeed")
result
end

# This can be added to the beginning of a test to verify that the
# box with the given name is available to a test. This will raise
# an exception if the box is not found.
def require_box(name)
if !File.exist?(box_path(name))
raise ArgumentError, "The tests should have a '#{name}' box."
end
end

# This is used to get the path to a box of a specific name.
def box_path(name)
File.join(config.box_directory, "#{name}.box")
end
end
4 changes: 3 additions & 1 deletion test/acceptance/up_basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

# This creates an initial environment that is ready for a "vagrant up"
def initialize_valid_environment
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
require_box("default")

assert_execute("vagrant", "box", "add", "base", box_path("default"))
assert_execute("vagrant", "init")
end

Expand Down

0 comments on commit a8909cb

Please sign in to comment.