Sha256: b5793105b0407918e6ea53d283b7c9935ae05625c1fe6fac62b2b4ad1a6e8a5d

Contents?: true

Size: 1.9 KB

Versions: 30

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true
require 'rubygems/package/tar_test_case'
require 'rubygems/package'

class TestGemPackageTarReader < Gem::Package::TarTestCase

  def test_each_entry
    tar = tar_dir_header "foo", "bar", 0, Time.now
    tar << tar_file_header("bar", "baz", 0, 0, Time.now)

    io = TempIO.new tar

    entries = 0

    Gem::Package::TarReader.new io do |tar_reader|
      tar_reader.each_entry do |entry|
        assert_kind_of Gem::Package::TarReader::Entry, entry

        entries += 1
      end
    end

    assert_equal 2, entries
  ensure
    io.close!
  end

  def test_rewind
    content = ('a'..'z').to_a.join(" ")

    str =
      tar_file_header("lib/foo", "", 010644, content.size, Time.now) +
        content + "\0" * (512 - content.size)
    str << "\0" * 1024

    io = TempIO.new(str)

    Gem::Package::TarReader.new(io) do |tar_reader|
      3.times do
        tar_reader.rewind
        i = 0
        tar_reader.each_entry do |entry|
          assert_equal(content, entry.read)
          i += 1
        end
        assert_equal(1, i)
      end
    end
  ensure
    io.close!
  end

  def test_seek
    tar = tar_dir_header "foo", "bar", 0, Time.now
    tar << tar_file_header("bar", "baz", 0, 0, Time.now)

    io = TempIO.new tar

    Gem::Package::TarReader.new io do |tar_reader|
      tar_reader.seek 'baz/bar' do |entry|
        assert_kind_of Gem::Package::TarReader::Entry, entry

        assert_equal 'baz/bar', entry.full_name
      end

      assert_equal 0, io.pos
    end
  ensure
    io.close!
  end

  def test_seek_missing
    tar = tar_dir_header "foo", "bar", 0, Time.now
    tar << tar_file_header("bar", "baz", 0, 0, Time.now)

    io = TempIO.new tar

    Gem::Package::TarReader.new io do |tar_reader|
      tar_reader.seek 'nonexistent' do |entry|
        flunk 'entry missing but entry-found block was run'
      end

      assert_equal 0, io.pos
    end
  ensure
    io.close!
  end

end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
rubygems-update-2.7.11 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.10 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.9 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.8 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.7 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.6 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.5 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.4 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.4.pre1 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.3 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.2 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.1 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.7.0 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.6.14 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.6.13 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.6.12 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.6.11 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.6.10 test/rubygems/test_gem_package_tar_reader.rb
rubygems-update-2.6.9 test/rubygems/test_gem_package_tar_reader.rb
ruby-compiler-0.1.1 vendor/ruby/test/rubygems/test_gem_package_tar_reader.rb