diff --git a/lib/vagrant/action/box/package.rb b/lib/vagrant/action/box/package.rb new file mode 100644 index 000000000..62588fb9c --- /dev/null +++ b/lib/vagrant/action/box/package.rb @@ -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 diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index e5d852c20..93071e261 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -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 diff --git a/test/vagrant/action/box/package_test.rb b/test/vagrant/action/box/package_test.rb new file mode 100644 index 000000000..d7d8c1e98 --- /dev/null +++ b/test/vagrant/action/box/package_test.rb @@ -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