--include added to package tests passing, but still needs manual verification
This commit is contained in:
parent
9e41bd9a34
commit
79718eb4c3
|
@ -21,7 +21,10 @@ Usage: #{command.full_name} #{all_options_string}
|
|||
Package the current vagrant environment into a box.
|
||||
|
||||
EOS
|
||||
|
||||
opt :include, "files to include in the package", :type => :strings
|
||||
|
||||
run do |command|
|
||||
Vagrant::Commands.package(command.argv[0])
|
||||
Vagrant::Commands.package(command.argv[0], command.opts[:include])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,13 @@ module Vagrant
|
|||
module VM
|
||||
class Package < Base
|
||||
attr_accessor :out_path
|
||||
attr_accessor :include_files
|
||||
attr_accessor :temp_path
|
||||
|
||||
def initialize(vm, out_path = nil, *args)
|
||||
def initialize(vm, out_path = nil, include_files = [], *args)
|
||||
super
|
||||
@out_path = out_path || "package"
|
||||
@include_files = include_files
|
||||
@temp_path = nil
|
||||
end
|
||||
|
||||
|
@ -29,6 +31,8 @@ module Vagrant
|
|||
logger.info "Packaging VM into #{tar_path} ..."
|
||||
Tar.open(tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU) do |tar|
|
||||
begin
|
||||
@include_files.each { |f| tar.append_file(f) }
|
||||
|
||||
# Append tree will append the entire directory tree unless a relative folder reference is used
|
||||
current_dir = FileUtils.pwd
|
||||
FileUtils.cd(temp_path)
|
||||
|
|
|
@ -113,14 +113,14 @@ error
|
|||
# Export and package the current vm
|
||||
#
|
||||
# This command requires that an instance be powered off
|
||||
def package(out_path=nil)
|
||||
def package(out_path=nil, include_files=[])
|
||||
Env.load!
|
||||
Env.require_persisted_vm
|
||||
error_and_exit(<<-error) unless Env.persisted_vm.powered_off?
|
||||
The vagrant virtual environment you are trying to package must be powered off
|
||||
error
|
||||
|
||||
Env.persisted_vm.package(out_path)
|
||||
Env.persisted_vm.package(out_path, include_files)
|
||||
end
|
||||
|
||||
# Manages the `vagrant box` command, allowing the user to add
|
||||
|
|
|
@ -19,9 +19,9 @@ module Vagrant
|
|||
@vm = vm
|
||||
end
|
||||
|
||||
def package(out_path)
|
||||
def package(out_path, include_files=[])
|
||||
add_action(Actions::VM::Export)
|
||||
add_action(Actions::VM::Package, out_path)
|
||||
add_action(Actions::VM::Package, out_path, include_files)
|
||||
execute!
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
|
||||
class PackageActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing")
|
||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", [])
|
||||
mock_config
|
||||
|
||||
@temp_path = "temp_path"
|
||||
|
@ -82,8 +82,22 @@ class PackageActionTest < Test::Unit::TestCase
|
|||
@action.compress
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
should "add included files when passed" do
|
||||
include_files = ['foo', 'bar']
|
||||
action = mock_action(Vagrant::Actions::VM::Package, "bing", include_files).last
|
||||
@tar.expects(:append_tree).with(".")
|
||||
include_files.each { |f| @tar.expects(:append_file).with(f) }
|
||||
action.compress
|
||||
end
|
||||
|
||||
should "not add files when none are specified" do
|
||||
@tar.expects(:append_tree).with(".")
|
||||
@tar.expects(:append_file).never
|
||||
@action.compress
|
||||
end
|
||||
end
|
||||
|
||||
context "export callback to set temp path" do
|
||||
should "save to the temp_path directory" do
|
||||
foo = mock("foo")
|
||||
|
|
|
@ -174,9 +174,16 @@ class CommandsTest < Test::Unit::TestCase
|
|||
Vagrant::Commands.package
|
||||
end
|
||||
|
||||
should "pass in the out path to the package method" do
|
||||
should "pass the out path and include_files to the package method" do
|
||||
out_path = mock("out_path")
|
||||
@persisted_vm.expects(:package).with(out_path).once
|
||||
include_files = mock("include_files")
|
||||
@persisted_vm.expects(:package).with(out_path, include_files).once
|
||||
Vagrant::Commands.package(out_path, include_files)
|
||||
end
|
||||
|
||||
should "default to an empty array when not include_files are specified" do
|
||||
out_path = mock("out_path")
|
||||
@persisted_vm.expects(:package).with(out_path, []).once
|
||||
Vagrant::Commands.package(out_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ class VMTest < Test::Unit::TestCase
|
|||
out_path = mock("out_path")
|
||||
action_seq = sequence("actions")
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Export).once.in_sequence(action_seq)
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Package, out_path).once.in_sequence(action_seq)
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Package, out_path, []).once.in_sequence(action_seq)
|
||||
@vm.expects(:execute!).in_sequence(action_seq)
|
||||
@vm.package(out_path)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue