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_output'
11 class TestGemPackageTarOutput < TarTestCase
16 @file = File.join @tempdir, 'bla2.tar'
20 open @file, 'wb' do |tar_io|
21 Gem::Package::TarOutput.open tar_io do |tar_writer|
22 tar_writer.add_file_simple 'README', 0, 17 do |io|
23 io.write "This is a README\n"
26 tar_writer.metadata = "This is some metadata\n"
32 name, data = files.shift
33 assert_equal 'data.tar.gz', name
35 gz = Zlib::GzipReader.new StringIO.new(data)
37 Gem::Package::TarReader.new gz do |tar_reader|
38 tar_reader.each do |entry|
39 assert_equal 'README', entry.full_name
40 assert_equal "This is a README\n", entry.read
46 name, data = files.shift
47 assert_equal 'metadata.gz', name
49 gz = Zlib::GzipReader.new StringIO.new(data)
50 assert_equal "This is some metadata\n", gz.read
57 if defined? OpenSSL then
58 def test_self_open_signed
59 signer = Gem::Security::Signer.new @private_key, [@public_cert]
61 open @file, 'wb' do |tar_io|
62 Gem::Package::TarOutput.open tar_io, signer do |tar_writer|
63 tar_writer.add_file_simple 'README', 0, 17 do |io|
64 io.write "This is a README\n"
67 tar_writer.metadata = "This is some metadata\n"
73 name, data = files.shift
74 assert_equal 'data.tar.gz', name
76 name, data = files.shift
77 assert_equal 'metadata.gz', name
79 name, data = files.shift
80 assert_equal 'data.tar.gz.sig', name
82 name, data = files.shift
83 assert_equal 'metadata.gz.sig', name
92 open @file, 'rb' do |io|
93 Gem::Package::TarReader.new io do |tar_reader|
94 tar_reader.each do |entry|
95 files << [entry.full_name, entry.read]