X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/95d1231a25637c5ba0fd07b116876b17711ec201..40d04a669958fb777f4cf4a93ae7e21d101a438f:/sdk/ruby/test/test_keep_manifest.rb diff --git a/sdk/ruby/test/test_keep_manifest.rb b/sdk/ruby/test/test_keep_manifest.rb index 64c8ea3129..2ad0941e04 100644 --- a/sdk/ruby/test/test_keep_manifest.rb +++ b/sdk/ruby/test/test_keep_manifest.rb @@ -1,21 +1,9 @@ -require "minitest/autorun" require "arvados/keep" - -def random_block(size=nil) - sprintf("%032x+%d", rand(16 ** 32), size || rand(64 * 1024 * 1024)) -end +require "minitest/autorun" +require "sdk_fixtures" class ManifestTest < Minitest::Test - SIMPLEST_MANIFEST = ". #{random_block(9)} 0:9:simple.txt\n" - MULTIBLOCK_FILE_MANIFEST = - [". #{random_block(8)} 0:4:repfile 4:4:uniqfile", - "./s1 #{random_block(6)} 0:3:repfile 3:3:uniqfile", - ". #{random_block(8)} 0:7:uniqfile2 7:1:repfile\n"].join("\n") - MULTILEVEL_MANIFEST = - [". #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n", - "./dir1 #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n", - "./dir1/subdir #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n", - "./dir2 #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n"].join("") + include SDKFixtures def check_stream(stream, exp_name, exp_blocks, exp_files) assert_equal(exp_name, stream.first) @@ -50,13 +38,30 @@ class ManifestTest < Minitest::Test seen << stream assert_equal(3, files.size, "wrong file count for stream #{stream}") end - assert_equal(4, seen.size, "wrong number of streams") + assert_equal(MULTILEVEL_MANIFEST.count("\n"), seen.size, + "wrong number of streams") end def test_empty_each_line assert_empty(Keep::Manifest.new("").each_line.to_a) end + def test_empty_each_file_spec + assert_empty(Keep::Manifest.new("").each_file_spec.to_a) + end + + def test_empty_files + assert_empty(Keep::Manifest.new("").files) + end + + def test_empty_files_count + assert_equal(0, Keep::Manifest.new("").files_count) + end + + def test_empty_has_file? + refute(Keep::Manifest.new("").has_file?("")) + end + def test_empty_line_within_manifest block_s = random_block manifest = Keep::Manifest. @@ -70,13 +75,12 @@ class ManifestTest < Minitest::Test end def test_backslash_escape_parsing - m_text = "./dir\\040name #{random_block} 0:0:file\\\\name\\011\\here.txt\n" - manifest = Keep::Manifest.new(m_text) + manifest = Keep::Manifest.new(MANY_ESCAPES_MANIFEST) streams = manifest.each_line.to_a assert_equal(1, streams.size, "wrong number of streams with whitespace") assert_equal("./dir name", streams.first.first, "wrong stream name with whitespace") - assert_equal(["0:0:file\\name\t\\here.txt"], streams.first.last, + assert_equal(["0:9:file\\name\t\\here.txt"], streams.first.last, "wrong filename(s) with whitespace") end @@ -101,10 +105,15 @@ class ManifestTest < Minitest::Test end def test_files_with_colons_in_names - manifest = Keep::Manifest.new(". #{random_block(9)} 0:9:file:test.txt\n") + manifest = Keep::Manifest.new(COLON_FILENAME_MANIFEST) assert_equal([[".", "file:test.txt", 9]], manifest.files) end + def test_files_with_escape_sequence_in_filename + manifest = Keep::Manifest.new(ESCAPED_FILENAME_MANIFEST) + assert_equal([[".", "a a.txt", 9]], manifest.files) + end + def test_files_spanning_multiple_blocks manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST) assert_equal([[".", "repfile", 5], @@ -153,4 +162,37 @@ class ManifestTest < Minitest::Test refute(manifest.has_file?("./s2/repfile"), "one-arg missing stream found") refute(manifest.has_file?("./s2", "repfile"), "two-arg missing stream found") end + + def test_has_file_with_spaces + manifest = Keep::Manifest.new(ESCAPED_FILENAME_MANIFEST) + assert(manifest.has_file?("./a a.txt"), "one-arg path not found") + assert(manifest.has_file?(".", "a a.txt"), "two-arg path not found") + refute(manifest.has_file?("a\\040\\141"), "one-arg unescaped found") + refute(manifest.has_file?(".", "a\\040\\141"), "two-arg unescaped found") + end + + def test_parse_all_fixtures + fixtures('collections').each do |name, collection| + parse_collection_manifest name, collection + end + end + + def test_raise_on_bogus_fixture + assert_raises ArgumentError do + parse_collection_manifest('bogus collection', + {'manifest_text' => ". zzz 0:\n"}) + end + end + + def parse_collection_manifest name, collection + manifest = Keep::Manifest.new(collection['manifest_text']) + manifest.each_file_spec do |stream_name, start_pos, file_size, file_name| + assert_kind_of String, stream_name + assert_kind_of Integer, start_pos + assert_kind_of Integer, file_size + assert_kind_of String, file_name + assert !stream_name.empty?, "empty stream_name in #{name} fixture" + assert !file_name.empty?, "empty file_name in #{name} fixture" + end + end end