diff --git a/tasks/acceptance.rake b/tasks/acceptance.rake index 93eeaafdd..331594ca2 100644 --- a/tasks/acceptance.rake +++ b/tasks/acceptance.rake @@ -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 @@ -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| diff --git a/test/acceptance/box_test.rb b/test/acceptance/box_test.rb index 9a02f458c..13e57a1f3 100644 --- a/test/acceptance/box_test.rb +++ b/test/acceptance/box_test.rb @@ -3,12 +3,6 @@ require File.expand_path("../base", __FILE__) 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) @@ -18,7 +12,7 @@ describe "vagrant box" do 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 @@ -52,7 +46,7 @@ describe "vagrant box" do # 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 @@ -62,12 +56,12 @@ describe "vagrant box" do 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 diff --git a/test/acceptance/ssh_test.rb b/test/acceptance/ssh_test.rb index 8ede322d3..8e9ae295f 100644 --- a/test/acceptance/ssh_test.rb +++ b/test/acceptance/ssh_test.rb @@ -7,7 +7,9 @@ describe "vagrant ssh" do 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") @@ -24,7 +26,9 @@ describe "vagrant ssh" do 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") diff --git a/test/acceptance/support/config.rb b/test/acceptance/support/config.rb index 6e1772ba2..894464293 100644 --- a/test/acceptance/support/config.rb +++ b/test/acceptance/support/config.rb @@ -8,7 +8,7 @@ module Acceptance 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") @@ -19,7 +19,7 @@ module Acceptance @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 @@ -34,10 +34,8 @@ module Acceptance 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 diff --git a/test/acceptance/support/shared/base_context.rb b/test/acceptance/support/shared/base_context.rb index fa0f48ea4..905b0cd25 100644 --- a/test/acceptance/support/shared/base_context.rb +++ b/test/acceptance/support/shared/base_context.rb @@ -48,4 +48,18 @@ shared_context "acceptance" do 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 diff --git a/test/acceptance/up_basic_test.rb b/test/acceptance/up_basic_test.rb index bf2829412..3f1d6524e 100644 --- a/test/acceptance/up_basic_test.rb +++ b/test/acceptance/up_basic_test.rb @@ -7,7 +7,9 @@ describe "vagrant up", "basics" do # 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