From c9cf2867eaf63bee4aeaacad305ed3214825b9f4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 3 Nov 2011 21:38:15 -0700 Subject: [PATCH] Some `vagrant box` tests --- .gitignore | 1 + test/acceptance/box_test.rb | 14 +++++++++++++ test/acceptance/helpers/config.rb | 21 +++++++++++++++++++ .../helpers/isolated_environment.rb | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/.gitignore b/.gitignore index bee88a907..e5005cf67 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # Vagrant stuff acceptance_config.yml +package.box Vagrantfile .vagrant diff --git a/test/acceptance/box_test.rb b/test/acceptance/box_test.rb index 55f580175..0164a250b 100644 --- a/test/acceptance/box_test.rb +++ b/test/acceptance/box_test.rb @@ -5,4 +5,18 @@ class BoxTest < AcceptanceTest result = execute("vagrant", "box", "list") assert result.stdout.read =~ /There are no installed boxes!/ end + + should "add a box from a file" do + if !config.boxes.has_key?("default") || !File.file?(config.boxes["default"]) + raise ArgumentError, "The configuration should specify a 'default' box." + end + + # 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") + assert(results.stdout.read =~ /^foo$/, "Box should exist after it is added") + end end diff --git a/test/acceptance/helpers/config.rb b/test/acceptance/helpers/config.rb index 21524a7d1..6e1772ba2 100644 --- a/test/acceptance/helpers/config.rb +++ b/test/acceptance/helpers/config.rb @@ -8,6 +8,7 @@ module Acceptance attr_reader :vagrant_path attr_reader :vagrant_version attr_reader :env + attr_reader :boxes def initialize(path) @logger = Log4r::Logger.new("acceptance::config") @@ -18,6 +19,26 @@ module Acceptance @vagrant_path = options["vagrant_path"] @vagrant_version = options["vagrant_version"] @env = options["env"] + @boxes = options["boxes"] + + # Verify the configuration object. + validate + end + + # This method verifies the configuration and makes sure that + # all the configuration is available and appears good. This + # method will raise an ArgumentError in the case that anything + # is wrong. + def validate + if !@vagrant_path || !File.file?(@vagrant_path) + 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." + end end end end diff --git a/test/acceptance/helpers/isolated_environment.rb b/test/acceptance/helpers/isolated_environment.rb index 39ff0ad32..6a9edacff 100644 --- a/test/acceptance/helpers/isolated_environment.rb +++ b/test/acceptance/helpers/isolated_environment.rb @@ -88,6 +88,10 @@ module Acceptance @stdout = stdout @stderr = stderr end + + def success? + @exit_status == 0 + end end end