From a8909cbb0bf3614ea59081172895670294b9dcae Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 13 Nov 2011 13:49:21 -0800 Subject: [PATCH] Acceptance tests now take a "box_directory" instead of paths to individual boxes --- tasks/acceptance.rake | 14 +++++++++----- test/acceptance/box_test.rb | 14 ++++---------- test/acceptance/ssh_test.rb | 8 ++++++-- test/acceptance/support/config.rb | 10 ++++------ test/acceptance/support/shared/base_context.rb | 14 ++++++++++++++ test/acceptance/up_basic_test.rb | 4 +++- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/tasks/acceptance.rake b/tasks/acceptance.rake index 93eeaafdd53..331594ca2b4 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 9a02f458c8b..13e57a1f353 100644 --- a/test/acceptance/box_test.rb +++ b/test/acceptance/box_test.rb @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/test/acceptance/ssh_test.rb b/test/acceptance/ssh_test.rb index 8ede322d343..8e9ae295f87 100644 --- a/test/acceptance/ssh_test.rb +++ b/test/acceptance/ssh_test.rb @@ -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") @@ -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") diff --git a/test/acceptance/support/config.rb b/test/acceptance/support/config.rb index 6e1772ba260..8944642937a 100644 --- a/test/acceptance/support/config.rb +++ b/test/acceptance/support/config.rb @@ -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") @@ -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 @@ -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 diff --git a/test/acceptance/support/shared/base_context.rb b/test/acceptance/support/shared/base_context.rb index fa0f48ea479..905b0cd2546 100644 --- a/test/acceptance/support/shared/base_context.rb +++ b/test/acceptance/support/shared/base_context.rb @@ -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 diff --git a/test/acceptance/up_basic_test.rb b/test/acceptance/up_basic_test.rb index bf282941269..3f1d6524e9b 100644 --- a/test/acceptance/up_basic_test.rb +++ b/test/acceptance/up_basic_test.rb @@ -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