Add action for box repackaging [closes GH-120]

This commit is contained in:
Mitchell Hashimoto 2010-07-28 07:35:58 -07:00
parent 01203c117c
commit b179ee6c76
3 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,19 @@
require 'vagrant/action/general/package'
module Vagrant
class Action
module Box
# Packages a box which has already been unpackaged (such as
# for the `vagrant box repackage` command) by leveraging the
# general packager middleware.
class Package < General::Package
# Alias instead of calling super for testability
alias_method :general_call, :call
def call(env)
env["package.directory"] = env["box"].directory
general_call(env)
end
end
end
end
end

View File

@ -110,6 +110,13 @@ module Vagrant
end
register :box_remove, box_remove
# box_repackage - Repackages a box.
box_repackage = Builder.new do
use Box::Package
end
register :box_repackage, box_repackage
end
end
end

View File

@ -0,0 +1,25 @@
require "test_helper"
class PackageBoxActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::Box::Package
@app, @env = mock_action_data
@env["box"] = Vagrant::Box.new(mock_environment, "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["box"].directory
true
end
@instance.call(@env)
end
end