2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
7 require File.join(File.expand_path(File.dirname(__FILE__)),
8 'gem_package_tar_test_case')
9 require 'rubygems/package/tar_input'
11 class TestGemPackageTarInput < TarTestCase
13 # Sometimes the setgid bit doesn't take. Don't know if this is a problem on
14 # all systems, or just some. But for now, we will ignore it in the tests.
20 inner_tar = tar_file_header("bla", "", 0612, 10)
21 inner_tar += "0123456789" + "\0" * 502
22 inner_tar += tar_file_header("foo", "", 0636, 5)
23 inner_tar += "01234" + "\0" * 507
24 inner_tar += tar_dir_header("__dir__", "", 0600)
25 inner_tar += "\0" * 1024
29 os = Zlib::GzipWriter.new str
37 @file = File.join @tempdir, 'bla.tar'
39 File.open @file, 'wb' do |f|
40 f.write tar_file_header("data.tar.gz", "", 0644, str.string.size)
42 f.write "\0" * ((512 - (str.string.size % 512)) % 512 )
44 @spec = Gem::Specification.new do |spec|
45 spec.author = "Mauricio :)"
50 f.write tar_file_header("metadata", "", 0644, meta.size)
51 f.write meta + "\0" * (1024 - meta.size)
55 @entry_names = %w{bla foo __dir__}
56 @entry_sizes = [10, 5, 0]
57 #FIXME: are these modes system dependent?
58 @entry_modes = [0100612, 0100636, 040600]
59 @entry_files = %W[#{@tempdir}/bla #{@tempdir}/foo]
60 @entry_contents = %w[0123456789 01234]
64 open @file, 'rb' do |io|
65 Gem::Package::TarInput.open io do |tar_input|
68 tar_input.each_with_index do |entry, i|
71 assert_kind_of Gem::Package::TarReader::Entry, entry
72 assert_equal @entry_names[i], entry.header.name
73 assert_equal @entry_sizes[i], entry.header.size
78 assert_equal @spec, tar_input.metadata
83 def test_extract_entry_works
84 open @file, 'rb' do |io|
85 Gem::Package::TarInput.open io do |tar_input|
86 assert_equal @spec, tar_input.metadata
90 tar_input.each_with_index do |entry, i|
92 tar_input.extract_entry @tempdir, entry
93 name = File.join @tempdir, entry.header.name
96 assert File.dir?(name)
98 assert File.file?(name)
99 assert_equal @entry_sizes[i], File.stat(name).size
103 unless Gem.win_platform? then
104 assert_equal @entry_modes[i], File.stat(name).mode & (~SETGID_BIT)
108 assert_equal 2, count
112 @entry_files.each_with_index do |x, i|
114 assert_equal @entry_contents[i], File.read_b(x)