Tests for Minitar update.
This commit is contained in:
parent
0c24f0e68f
commit
dfe67d71de
|
@ -38,20 +38,24 @@ module Vagrant
|
||||||
|
|
||||||
def compress
|
def compress
|
||||||
logger.info "Packaging VM into #{tar_path} ..."
|
logger.info "Packaging VM into #{tar_path} ..."
|
||||||
open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar|
|
File.open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar|
|
||||||
begin
|
Archive::Tar::Minitar::Output.open(tar) do |output|
|
||||||
current_dir = FileUtils.pwd
|
begin
|
||||||
@include_files.each do |f|
|
current_dir = FileUtils.pwd
|
||||||
logger.info "Packaging additional file: #{f}"
|
|
||||||
Archive::Tar::Minitar.pack(f, tar)
|
include_files.each do |f|
|
||||||
|
logger.info "Packaging additional file: #{f}"
|
||||||
|
Archive::Tar::Minitar.pack_file(f, output)
|
||||||
|
end
|
||||||
|
|
||||||
|
FileUtils.cd(temp_path)
|
||||||
|
|
||||||
|
Dir.glob(File.join(".", "*")).each do |entry|
|
||||||
|
Archive::Tar::Minitar.pack_file(entry, output)
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
FileUtils.cd(current_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
FileUtils.cd(temp_path)
|
|
||||||
|
|
||||||
# Append tree will append the entire directory tree unless a relative folder reference is used
|
|
||||||
Archive::Tar::Minitar.pack(".", tar)
|
|
||||||
ensure
|
|
||||||
FileUtils.cd(current_dir)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -84,6 +84,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@action.stubs(:box_dir).returns(@box_dir)
|
@action.stubs(:box_dir).returns(@box_dir)
|
||||||
Dir.stubs(:chdir).yields
|
Dir.stubs(:chdir).yields
|
||||||
|
Archive::Tar::Minitar.stubs(:unpack)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "change to the box directory" do
|
should "change to the box directory" do
|
||||||
|
@ -92,9 +93,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "open the tar file within the new directory, and extract it all" do
|
should "open the tar file within the new directory, and extract it all" do
|
||||||
@tar = mock("tar")
|
Archive::Tar::Minitar.expects(:unpack).with(@runner.temp_path, @box_dir).once
|
||||||
@tar.expects(:extract_all).once
|
|
||||||
Tar.expects(:open).with(@runner.temp_path, anything, anything, anything).yields(@tar)
|
|
||||||
@action.decompress
|
@action.decompress
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,27 +66,49 @@ class PackageActionTest < Test::Unit::TestCase
|
||||||
@temp_path = "foo"
|
@temp_path = "foo"
|
||||||
@action.stubs(:temp_path).returns(@temp_path)
|
@action.stubs(:temp_path).returns(@temp_path)
|
||||||
|
|
||||||
|
@include_files = []
|
||||||
|
@action.stubs(:include_files).returns(@include_files)
|
||||||
|
|
||||||
@pwd = "bar"
|
@pwd = "bar"
|
||||||
FileUtils.stubs(:pwd).returns(@pwd)
|
FileUtils.stubs(:pwd).returns(@pwd)
|
||||||
FileUtils.stubs(:cd)
|
FileUtils.stubs(:cd)
|
||||||
|
|
||||||
@tar = mock("tar")
|
@file = mock("file")
|
||||||
Tar.stubs(:open).yields(@tar)
|
File.stubs(:open).yields(@file)
|
||||||
|
|
||||||
|
@output = mock("output")
|
||||||
|
@tar = Archive::Tar::Minitar
|
||||||
|
Archive::Tar::Minitar::Output.stubs(:open).yields(@output)
|
||||||
|
@tar.stubs(:pack_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "open the tar file with the tar path properly" do
|
should "open the tar file with the tar path properly" do
|
||||||
Tar.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU).once
|
File.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644).once
|
||||||
|
@action.compress
|
||||||
|
end
|
||||||
|
|
||||||
|
should "open tar file" do
|
||||||
|
Archive::Tar::Minitar::Output.expects(:open).with(@file).once
|
||||||
@action.compress
|
@action.compress
|
||||||
end
|
end
|
||||||
|
|
||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
# Methods below this comment test the block yielded by Tar.open
|
# Methods below this comment test the block yielded by Minitar open
|
||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
should "cd to the directory and append the directory" do
|
should "cd to the directory and append the directory" do
|
||||||
|
@files = []
|
||||||
compress_seq = sequence("compress_seq")
|
compress_seq = sequence("compress_seq")
|
||||||
|
|
||||||
FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
|
FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
|
||||||
FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq)
|
FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq)
|
||||||
@tar.expects(:append_tree).with(".").in_sequence(compress_seq)
|
Dir.expects(:glob).returns(@files).in_sequence(compress_seq)
|
||||||
|
|
||||||
|
5.times do |i|
|
||||||
|
file = mock("file#{i}")
|
||||||
|
@tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
|
||||||
|
@files << file
|
||||||
|
end
|
||||||
|
|
||||||
FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq)
|
FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq)
|
||||||
@action.compress
|
@action.compress
|
||||||
end
|
end
|
||||||
|
@ -102,17 +124,21 @@ class PackageActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "add included files when passed" do
|
should "add included files when passed" do
|
||||||
include_files = ['foo', 'bar']
|
compress_seq = sequence("compress")
|
||||||
action = mock_action(Vagrant::Actions::VM::Package, "bing", include_files).last
|
@files = []
|
||||||
action.stubs(:temp_path).returns("foo")
|
5.times do |i|
|
||||||
@tar.expects(:append_tree).with(".")
|
file = mock("file#{i}")
|
||||||
include_files.each { |f| @tar.expects(:append_file).with(f) }
|
@tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
|
||||||
action.compress
|
@files << file
|
||||||
|
end
|
||||||
|
|
||||||
|
@action.expects(:include_files).returns(@files)
|
||||||
|
@action.compress
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not add files when none are specified" do
|
should "not add files when none are specified" do
|
||||||
@tar.expects(:append_tree).with(".")
|
@tar.expects(:pack_file).never
|
||||||
@tar.expects(:append_file).never
|
Dir.expects(:glob).once.returns([])
|
||||||
@action.compress
|
@action.compress
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue