VM::Package middleware which will properly setup env data for General::Package

This commit is contained in:
Mitchell Hashimoto 2010-07-28 07:23:59 -07:00
parent 523cb1042a
commit 01203c117c
5 changed files with 49 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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