From 01203c117ce6f18477e53a9232ed067abeee178b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 28 Jul 2010 07:23:59 -0700 Subject: [PATCH] VM::Package middleware which will properly setup env data for General::Package --- lib/vagrant/action/builtin.rb | 2 +- lib/vagrant/action/vm/export.rb | 1 - lib/vagrant/action/vm/package.rb | 23 +++++++++++++++++++++++ test/vagrant/action/vm/export_test.rb | 1 - test/vagrant/action/vm/package_test.rb | 25 +++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 lib/vagrant/action/vm/package.rb create mode 100644 test/vagrant/action/vm/package_test.rb diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index c516cd22f..e5d852c20 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -90,7 +90,7 @@ module Vagrant use VM::ClearSharedFolders use VM::Export use VM::PackageVagrantfile - use General::Package + use VM::Package end register :package, package diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index cf8ba1ce3..e4c7e0909 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -32,7 +32,6 @@ module Vagrant def setup_temp_dir @env.logger.info "Creating temporary directory for export..." @temp_dir = @env["export.temp_dir"] = File.join(@env.env.tmp_path, Time.now.to_i.to_s) - @env["package.directory"] = @temp_dir # TODO temporary FileUtils.mkpath(@env["export.temp_dir"]) end diff --git a/lib/vagrant/action/vm/package.rb b/lib/vagrant/action/vm/package.rb new file mode 100644 index 000000000..e27b94e56 --- /dev/null +++ b/lib/vagrant/action/vm/package.rb @@ -0,0 +1,23 @@ +require 'vagrant/action/general/package' + +module Vagrant + class Action + module VM + # A subclass of {General::Package} which simply makes sure that + # the package directory is set to the directory which the VM + # was exported to. + class Package < General::Package + # Doing this so that we can test that the parent is properly + # called in the unit tests. + alias_method :general_call, :call + def call(env) + # Just match up a couple environmental variables so that + # the superclass will do the right thing. Then, call the + # superclass + env["package.directory"] = env["export.temp_dir"] + general_call(env) + end + end + end + end +end diff --git a/test/vagrant/action/vm/export_test.rb b/test/vagrant/action/vm/export_test.rb index dc06384ed..9efebded9 100644 --- a/test/vagrant/action/vm/export_test.rb +++ b/test/vagrant/action/vm/export_test.rb @@ -106,7 +106,6 @@ class ExportVMActionTest < Test::Unit::TestCase should "set to the environment" do @instance.setup_temp_dir assert_equal @temp_dir, @env["export.temp_dir"] - assert_equal @temp_dir, @env["package.directory"] assert_equal @temp_dir, @instance.temp_dir end end diff --git a/test/vagrant/action/vm/package_test.rb b/test/vagrant/action/vm/package_test.rb new file mode 100644 index 000000000..2f79bf729 --- /dev/null +++ b/test/vagrant/action/vm/package_test.rb @@ -0,0 +1,25 @@ +require "test_helper" + +class PackageVMActionTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Action::VM::Package + @app, @env = mock_action_data + @env["export.temp_dir"] = "foo" + + @instance = @klass.new(@app, @env) + end + + should "be a subclass of general packaging middleware" do + assert @instance.is_a?(Vagrant::Action::General::Package) + end + + should "set the package directory then call parent" do + @instance.expects(:general_call).once.with() do |env| + assert env["package.directory"] + assert_equal env["package.directory"], env["export.temp_dir"] + true + end + + @instance.call(@env) + end +end