Class: CPIOArchiveReaderTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/excavate/extractors/cpio/cpio_old_format.rb

Constant Summary collapse

CPIOFixture =
StringIO.new(DATA.read)
ExpectedFixtureHashes =

These are SHA1 hashes

{ 'cpio_test/test_executable'    => '97bd38305a81f2d89b5f3aa44500ec964b87cf8a',
'cpio_test/test_dir/test_file' => 'e7f1aa55a7f83dc99c9978b91072d01a3f5c812e' }

Instance Method Summary collapse

Instance Method Details

#test_given_a_archive_with_a_bad_magic_number_should_raiseObject



288
289
290
291
292
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 288

def test_given_a_archive_with_a_bad_magic_number_should_raise
  assert_raises(CPIO::ArchiveFormatError) do
    CPIO::ArchiveReader.new(StringIO.new('foo')).each_entry { }
  end
end

#test_given_a_archive_with_a_valid_magic_number_should_not_raiseObject



294
295
296
297
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 294

def test_given_a_archive_with_a_valid_magic_number_should_not_raise
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  assert_nil archive.each_entry { }
end

#test_given_a_valid_archive_should_have_correct_file_contentsObject



334
335
336
337
338
339
340
341
342
343
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 334

def test_given_a_valid_archive_should_have_correct_file_contents
  expected = ExpectedFixtureHashes.size
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  archive.each_entry do |ent|
    if (sha1_hash = ExpectedFixtureHashes[ent.filename]) && Digest::SHA1.hexdigest(ent.data) == sha1_hash
      expected -= 1
    end
  end
  assert_equal 0, expected, "Expected all files in the archive to hash correctly."
end

#test_given_a_valid_archive_should_have_the_expected_entry_filenamesObject



306
307
308
309
310
311
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 306

def test_given_a_valid_archive_should_have_the_expected_entry_filenames
  expected = %w[cpio_test cpio_test/test_dir cpio_test/test_dir/test_file cpio_test/test_executable]
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  archive.each_entry { |ent| expected.delete(ent.filename) }
  assert_equal 0, expected.size, "The expected array should be empty but we still have: #{expected.inspect}"
end

#test_given_a_valid_archive_should_have_the_expected_number_of_directoriesObject



313
314
315
316
317
318
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 313

def test_given_a_valid_archive_should_have_the_expected_number_of_directories
  expected = 2
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  archive.each_entry { |ent| expected -= 1 if ent.directory? }
  assert_equal 0, expected
end

#test_given_a_valid_archive_should_have_the_expected_number_of_entriesObject



299
300
301
302
303
304
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 299

def test_given_a_valid_archive_should_have_the_expected_number_of_entries
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  entries = 4
  archive.each_entry { |ent| entries -= 1 }
  assert_equal 0, entries, "Expected #{entries} in the archive."
end

#test_given_a_valid_archive_should_have_the_expected_number_of_executable_filesObject



327
328
329
330
331
332
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 327

def test_given_a_valid_archive_should_have_the_expected_number_of_executable_files
  expected = 1
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  archive.each_entry { |ent| expected -= 1 if ent.file? && ent.executable? }
  assert_equal 0, expected
end

#test_given_a_valid_archive_should_have_the_expected_number_of_regular_filesObject



320
321
322
323
324
325
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 320

def test_given_a_valid_archive_should_have_the_expected_number_of_regular_files
  expected = 1
  archive = CPIO::ArchiveReader.new(CPIOFixture)
  archive.each_entry { |ent| expected -= 1 if ent.file? && !ent.executable? }
  assert_equal 0, expected
end