Moved the packaging action out to the General namespace, since it is now generalized
This commit is contained in:
parent
39bf56f786
commit
523cb1042a
|
@ -90,7 +90,7 @@ module Vagrant
|
|||
use VM::ClearSharedFolders
|
||||
use VM::Export
|
||||
use VM::PackageVagrantfile
|
||||
use VM::Package
|
||||
use General::Package
|
||||
end
|
||||
|
||||
register :package, package
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
module VM
|
||||
module General
|
||||
# A general packaging (tar) middleware. Given the following options,
|
||||
# it will do the right thing:
|
||||
#
|
||||
# * package.output - The filename of the outputted package.
|
||||
# * package.include - An array of files to include in the package.
|
||||
# * package.directory - The directory which contains the contents to
|
||||
# compress into the package.
|
||||
#
|
||||
# This middleware always produces the final file in the current working
|
||||
# directory (FileUtils.pwd)
|
||||
class Package
|
||||
include Util
|
||||
|
||||
|
@ -9,14 +19,13 @@ module Vagrant
|
|||
@env = env
|
||||
@env["package.output"] ||= env["config"].package.name
|
||||
@env["package.include"] ||= []
|
||||
|
||||
env.error!(:box_file_exists, :output_file => tar_path) if File.exist?(tar_path)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@env = env
|
||||
|
||||
return env.error!(:package_requires_export) if !@env["package.directory"]
|
||||
return env.error!(:package_output_exists) if File.exist?(tar_path)
|
||||
return env.error!(:package_requires_directory) if !@env["package.directory"]
|
||||
return if !verify_included_files
|
||||
compress
|
||||
|
|
@ -176,6 +176,13 @@
|
|||
specific VM must be specified. This can be done by calling
|
||||
`vagrant package NAME` where NAME is a valid VM represented by
|
||||
your Vagrantfile.
|
||||
:package_output_exists: |-
|
||||
The specified file to save the package as already exists. Please
|
||||
remove this file or specify a different filename for outputting.
|
||||
:package_requires_directory: |-
|
||||
A directory was not specified to package. This is an internal
|
||||
issue. Please send the relevant stack trace (if any) and information
|
||||
about this issue to the Vagrant team.
|
||||
:package_requires_export: |-
|
||||
Package must be used in conjunction with export.
|
||||
:provisioner_invalid_class: |-
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
require "test_helper"
|
||||
|
||||
class PackageVMActionTest < Test::Unit::TestCase
|
||||
class PackageGeneralActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::VM::Package
|
||||
@klass = Vagrant::Action::General::Package
|
||||
@app, @env = mock_action_data
|
||||
|
||||
@vm = mock("vm")
|
||||
@env["vm"] = @vm
|
||||
|
||||
@internal_vm = mock("internal")
|
||||
@vm.stubs(:vm).returns(@internal_vm)
|
||||
end
|
||||
|
||||
context "initializing" do
|
||||
|
@ -24,13 +21,6 @@ class PackageVMActionTest < Test::Unit::TestCase
|
|||
assert !@env.error?
|
||||
end
|
||||
|
||||
should "error the environment if the output file exists" do
|
||||
File.stubs(:exist?).with(@tar_path).returns(true)
|
||||
@klass.new(@app, @env)
|
||||
assert @env.error?
|
||||
assert_equal :box_file_exists, @env.error.first
|
||||
end
|
||||
|
||||
should "set the output path to configured by default" do
|
||||
@klass.new(@app, @env)
|
||||
assert_equal @env["config"].package.name, @env["package.output"]
|
||||
|
@ -81,13 +71,22 @@ class PackageVMActionTest < Test::Unit::TestCase
|
|||
@instance.call(@env)
|
||||
end
|
||||
|
||||
should "halt the chain if export didn't run" do
|
||||
should "halt the chain if the output file already exists" do
|
||||
File.expects(:exist?).returns(true)
|
||||
@app.expects(:call).never
|
||||
@instance.call(@env)
|
||||
|
||||
assert @env.error?
|
||||
assert_equal :package_output_exists, @env.error.first
|
||||
end
|
||||
|
||||
should "halt the chain if directory isn't set" do
|
||||
@env["package.directory"] = nil
|
||||
@app.expects(:call).never
|
||||
@instance.call(@env)
|
||||
|
||||
assert @env.error?
|
||||
assert_equal :package_requires_export, @env.error.first
|
||||
assert_equal :package_requires_directory, @env.error.first
|
||||
end
|
||||
|
||||
should "run cleanup if environment errors" do
|
Loading…
Reference in New Issue