Sha256: 1392c95276852cc6e9478fdb782f911ab796f2591794f37c9a1e316d37ac1cea

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/env ruby

require "minitar"
require "minitest_helper"

class TestTarOutput < Minitest::Test
  NAMES = ["a", "b", "c", "d" * 200]

  def setup
    FileUtils.mkdir_p("data__")
    NAMES.each do |filename|
      name = File.join("data__", filename)
      File.open(name, "wb") { |f|
        f.puts "#{name}: 123456789012345678901234567890"
      }
    end
    @tarfile = "data__/bla2.tar"
  end

  def teardown
    FileUtils.rm_rf("data__")
  end

  def test_open_no_block
    output = Minitar::Output.open(@tarfile)
    refute output.closed?
  ensure
    output.close
    assert output.closed?
  end

  def test_file_looks_good
    Minitar::Output.open(@tarfile) do |os|
      Dir.chdir("data__") do
        NAMES.each do |name|
          stat = File.stat(name)
          opts = {:size => stat.size, :mode => 0o644}
          os.tar.add_file_simple(name, opts) do |ss|
            File.open(name, "rb") { |ff| ss.write(ff.read(4096)) until ff.eof? }
          end
        end
      end
    end
    ff = File.open(@tarfile, "rb")
    Minitar::Reader.open(ff) do |is|
      names_from_tar = is.map do |entry|
        entry.name
      end
      assert_equal(NAMES, names_from_tar)
    end
  ensure
    ff.close if ff
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/minitar-0.12/test/test_tar_output.rb
minitar-0.12.1 test/test_tar_output.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/minitar-0.12/test/test_tar_output.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/minitar-0.12/test/test_tar_output.rb
minitar-0.12 test/test_tar_output.rb