1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rubygems/test_gem_package_tar_output.rb
nobu b551e8c8b3 * lib/rubygems: update to 1.3.6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-22 02:52:35 +00:00

97 lines
2.1 KiB
Ruby

require_relative 'gem_package_tar_test_case'
require 'rubygems/package/tar_output'
class TestGemPackageTarOutput < TarTestCase
def setup
super
@file = File.join @tempdir, 'bla2.tar'
end
def test_self_open
open @file, 'wb' do |tar_io|
Gem::Package::TarOutput.open tar_io do |tar_writer|
tar_writer.add_file_simple 'README', 0, 17 do |io|
io.write "This is a README\n"
end
tar_writer.metadata = "This is some metadata\n"
end
end
files = util_extract
name, data = files.shift
assert_equal 'data.tar.gz', name
gz = Zlib::GzipReader.new StringIO.new(data)
Gem::Package::TarReader.new gz do |tar_reader|
tar_reader.each do |entry|
assert_equal 'README', entry.full_name
assert_equal "This is a README\n", entry.read
end
end
gz.close
name, data = files.shift
assert_equal 'metadata.gz', name
gz = Zlib::GzipReader.new StringIO.new(data)
assert_equal "This is some metadata\n", gz.read
assert_empty files
ensure
gz.close if gz
end
if defined? OpenSSL then
def test_self_open_signed
signer = Gem::Security::Signer.new @private_key, [@public_cert]
open @file, 'wb' do |tar_io|
Gem::Package::TarOutput.open tar_io, signer do |tar_writer|
tar_writer.add_file_simple 'README', 0, 17 do |io|
io.write "This is a README\n"
end
tar_writer.metadata = "This is some metadata\n"
end
end
files = util_extract
name, data = files.shift
assert_equal 'data.tar.gz', name
name, data = files.shift
assert_equal 'metadata.gz', name
name, data = files.shift
assert_equal 'data.tar.gz.sig', name
name, data = files.shift
assert_equal 'metadata.gz.sig', name
assert_empty files
end
end
def util_extract
files = []
open @file, 'rb' do |io|
Gem::Package::TarReader.new io do |tar_reader|
tar_reader.each do |entry|
files << [entry.full_name, entry.read]
end
end
end
files
end
end