1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
6 require "minitest/autorun"
9 class ManifestTest < Minitest::Test
12 def check_stream(stream, exp_name, exp_blocks, exp_files)
13 assert_equal(exp_name, stream.first)
14 assert_equal(exp_blocks, stream[1].map(&:to_s))
15 assert_equal(exp_files, stream.last)
18 def test_simple_each_line_array
19 manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
20 stream_name, block_s, file = SIMPLEST_MANIFEST.strip.split
21 stream_a = manifest.each_line.to_a
22 assert_equal(1, stream_a.size, "wrong number of streams")
23 check_stream(stream_a.first, stream_name, [block_s], [file])
26 def test_simple_each_line_block
27 manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
29 manifest.each_line do |stream, blocks, files|
32 assert_equal([[SIMPLEST_MANIFEST.split.last]], result,
33 "wrong result from each_line block")
36 def test_multilevel_each_line
37 manifest = Keep::Manifest.new(MULTILEVEL_MANIFEST)
39 manifest.each_line do |stream, blocks, files|
40 refute(seen.include?(stream),
41 "each_line already yielded stream #{stream}")
43 assert_equal(3, files.size, "wrong file count for stream #{stream}")
45 assert_equal(MULTILEVEL_MANIFEST.count("\n"), seen.size,
46 "wrong number of streams")
49 def test_empty_each_line
50 assert_empty(Keep::Manifest.new("").each_line.to_a)
53 def test_empty_each_file_spec
54 assert_empty(Keep::Manifest.new("").each_file_spec.to_a)
58 assert_empty(Keep::Manifest.new("").files)
61 def test_empty_files_count
62 assert_equal(0, Keep::Manifest.new("").files_count)
65 def test_empty_dir_files_count
67 Keep::Manifest.new("./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\n").files_count)
70 def test_empty_files_size
71 assert_equal(0, Keep::Manifest.new("").files_size)
74 def test_empty_has_file?
75 refute(Keep::Manifest.new("").has_file?(""))
78 def test_empty_line_within_manifest
79 block_s = random_block
80 manifest = Keep::Manifest.
81 new([". #{block_s} 0:1:file1 1:2:file2\n",
83 ". #{block_s} 3:3:file3 6:4:file4\n"].join(""))
84 streams = manifest.each_line.to_a
85 assert_equal(2, streams.size)
86 check_stream(streams[0], ".", [block_s], ["0:1:file1", "1:2:file2"])
87 check_stream(streams[1], ".", [block_s], ["3:3:file3", "6:4:file4"])
90 def test_backslash_escape_parsing
91 manifest = Keep::Manifest.new(MANY_ESCAPES_MANIFEST)
92 streams = manifest.each_line.to_a
93 assert_equal(1, streams.size, "wrong number of streams with whitespace")
94 assert_equal("./dir name", streams.first.first,
95 "wrong stream name with whitespace")
96 assert_equal(["0:9:file\\name\t\\here.txt"], streams.first.last,
97 "wrong filename(s) with whitespace")
100 def test_simple_files
101 manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
102 assert_equal([[".", "simple.txt", 9]], manifest.files)
105 def test_multilevel_files
106 manifest = Keep::Manifest.new(MULTILEVEL_MANIFEST)
107 seen = Hash.new { |this, key| this[key] = [] }
108 manifest.files.each do |stream, basename, size|
109 refute(seen[stream].include?(basename),
110 "each_file repeated #{stream}/#{basename}")
111 seen[stream] << basename
112 assert_equal(3, size, "wrong size for #{stream}/#{basename}")
114 seen.each_pair do |stream, basenames|
115 assert_equal(%w(file1 file2 file3), basenames.sort,
116 "wrong file list for #{stream}")
120 def test_files_with_colons_in_names
121 manifest = Keep::Manifest.new(COLON_FILENAME_MANIFEST)
122 assert_equal([[".", "file:test.txt", 9]], manifest.files)
125 def test_files_with_escape_sequence_in_filename
126 manifest = Keep::Manifest.new(ESCAPED_FILENAME_MANIFEST)
127 assert_equal([[".", "a a.txt", 9]], manifest.files)
130 def test_files_spanning_multiple_blocks
131 manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
132 assert_equal([[".", "repfile", 5],
133 [".", "uniqfile", 4],
134 [".", "uniqfile2", 7],
135 ["./s1", "repfile", 3],
136 ["./s1", "uniqfile", 3]],
140 def test_minimum_file_count_simple
141 manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
142 assert(manifest.minimum_file_count?(1), "real minimum file count false")
143 refute(manifest.minimum_file_count?(2), "fake minimum file count true")
146 def test_minimum_file_count_multiblock
147 manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
148 assert(manifest.minimum_file_count?(2), "low minimum file count false")
149 assert(manifest.minimum_file_count?(5), "real minimum file count false")
150 refute(manifest.minimum_file_count?(6), "fake minimum file count true")
153 def test_exact_file_count_simple
154 manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
155 assert(manifest.exact_file_count?(1), "exact file count false")
156 refute(manifest.exact_file_count?(0), "-1 file count true")
157 refute(manifest.exact_file_count?(2), "+1 file count true")
160 def test_exact_file_count_multiblock
161 manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
162 assert(manifest.exact_file_count?(5), "exact file count false")
163 refute(manifest.exact_file_count?(4), "-1 file count true")
164 refute(manifest.exact_file_count?(6), "+1 file count true")
167 def test_files_size_multiblock
168 assert_equal(22, Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST).files_size)
171 def test_files_size_with_skipped_overlapping_data
172 manifest = Keep::Manifest.new(". #{random_block(9)} 3:3:f1 5:3:f2\n")
173 assert_equal(6, manifest.files_size)
177 manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
178 assert(manifest.has_file?("./repfile"), "one-arg repfile not found")
179 assert(manifest.has_file?(".", "repfile"), "two-arg repfile not found")
180 assert(manifest.has_file?("./s1/repfile"), "one-arg s1/repfile not found")
181 assert(manifest.has_file?("./s1", "repfile"), "two-arg s1/repfile not found")
182 refute(manifest.has_file?("./s1/uniqfile2"), "one-arg missing file found")
183 refute(manifest.has_file?("./s1", "uniqfile2"), "two-arg missing file found")
184 refute(manifest.has_file?("./s2/repfile"), "one-arg missing stream found")
185 refute(manifest.has_file?("./s2", "repfile"), "two-arg missing stream found")
188 def test_has_file_with_spaces
189 manifest = Keep::Manifest.new(ESCAPED_FILENAME_MANIFEST)
190 assert(manifest.has_file?("./a a.txt"), "one-arg path not found")
191 assert(manifest.has_file?(".", "a a.txt"), "two-arg path not found")
192 refute(manifest.has_file?("a\\040\\141"), "one-arg unescaped found")
193 refute(manifest.has_file?(".", "a\\040\\141"), "two-arg unescaped found")
196 def test_parse_all_fixtures
197 fixtures('collections').each do |name, collection|
198 parse_collection_manifest name, collection
202 def test_raise_on_bogus_fixture
203 assert_raises ArgumentError do
204 parse_collection_manifest('bogus collection',
205 {'manifest_text' => ". zzz 0:\n"})
209 def parse_collection_manifest name, collection
210 manifest = Keep::Manifest.new(collection['manifest_text'])
211 manifest.each_file_spec do |stream_name, start_pos, file_size, file_name|
212 assert_kind_of String, stream_name
213 assert_kind_of Integer, start_pos
214 assert_kind_of Integer, file_size
215 assert_kind_of String, file_name
216 assert !stream_name.empty?, "empty stream_name in #{name} fixture"
217 assert !file_name.empty?, "empty file_name in #{name} fixture"
221 def test_collection_with_dirs_in_filenames
222 manifest = Keep::Manifest.new(MANIFEST_WITH_DIRS_IN_FILENAMES)
224 seen = Hash.new { |this, key| this[key] = [] }
226 manifest.files.each do |stream, basename, size|
227 refute(seen[stream].include?(basename), "each_file repeated #{stream}/#{basename}")
228 assert_equal(3, size, "wrong size for #{stream}/#{basename}")
229 seen[stream] << basename
232 assert_equal(%w(. ./dir1 ./dir1/dir2), seen.keys)
234 seen.each_pair do |stream, basenames|
235 assert_equal(%w(file1), basenames.sort, "wrong file list for #{stream}")
239 def test_multilevel_collection_with_dirs_in_filenames
240 manifest = Keep::Manifest.new(MULTILEVEL_MANIFEST_WITH_DIRS_IN_FILENAMES)
242 seen = Hash.new { |this, key| this[key] = [] }
243 expected_sizes = {'.' => 3, './dir1' => 6, './dir1/dir2' => 11}
245 manifest.files.each do |stream, basename, size|
246 refute(seen[stream].include?(basename), "each_file repeated #{stream}/#{basename}")
247 assert_equal(expected_sizes[stream], size, "wrong size for #{stream}/#{basename}")
248 seen[stream] << basename
251 assert_equal(%w(. ./dir1 ./dir1/dir2), seen.keys)
253 seen.each_pair do |stream, basenames|
254 assert_equal(%w(file1), basenames.sort, "wrong file list for #{stream}")
260 [false, 'd41d8cd98f00b204e9800998ecf8427'],
261 [false, 'd41d8cd98f00b204e9800998ecf8427+0'],
262 [false, 'd41d8cd98f00b204e9800998ecf8427e0'],
263 [false, 'd41d8cd98f00b204e9800998ecf8427e0+0'],
264 [false, 'd41d8cd98f00b204e9800998ecf8427e+0 '],
265 [false, "d41d8cd98f00b204e9800998ecf8427e+0\n"],
266 [false, ' d41d8cd98f00b204e9800998ecf8427e+0'],
267 [false, 'd41d8cd98f00b204e9800998ecf8427e+K+0'],
268 [false, 'd41d8cd98f00b204e9800998ecf8427e+0+0'],
269 [false, 'd41d8cd98f00b204e9800998ecf8427e++'],
270 [false, 'd41d8cd98f00b204e9800998ecf8427e+0+K+'],
271 [false, 'd41d8cd98f00b204e9800998ecf8427e+0++K'],
272 [false, 'd41d8cd98f00b204e9800998ecf8427e+0+K++'],
273 [false, 'd41d8cd98f00b204e9800998ecf8427e+0+K++Z'],
274 [true, 'd41d8cd98f00b204e9800998ecf8427e', nil,nil,nil],
275 [true, 'd41d8cd98f00b204e9800998ecf8427e+0', '+0','0',nil],
276 [true, 'd41d8cd98f00b204e9800998ecf8427e+0+Fizz+Buzz','+0','0','+Fizz+Buzz'],
277 [true, 'd41d8cd98f00b204e9800998ecf8427e+Fizz+Buzz', nil,nil,'+Fizz+Buzz'],
278 [true, 'd41d8cd98f00b204e9800998ecf8427e+0+Ad41d8cd98f00b204e9800998ecf8427e00000000+Foo', '+0','0','+Ad41d8cd98f00b204e9800998ecf8427e00000000+Foo'],
279 [true, 'd41d8cd98f00b204e9800998ecf8427e+Ad41d8cd98f00b204e9800998ecf8427e00000000+Foo', nil,nil,'+Ad41d8cd98f00b204e9800998ecf8427e00000000+Foo'],
280 [true, 'd41d8cd98f00b204e9800998ecf8427e+0+Z', '+0','0','+Z'],
281 [true, 'd41d8cd98f00b204e9800998ecf8427e+Z', nil,nil,'+Z'],
282 ].each do |ok, locator, match2, match3, match4|
283 define_method "test_LOCATOR_REGEXP_on_#{locator.inspect}" do
284 match = Keep::Locator::LOCATOR_REGEXP.match locator
285 assert_equal ok, !!match
287 assert_equal match2, match[2]
288 assert_equal match3, match[3]
289 assert_equal match4, match[4]
292 define_method "test_parse_method_on_#{locator.inspect}" do
293 loc = Keep::Locator.parse locator
298 assert loc.is_a?(Keep::Locator)
301 #assert loc.hints.is_a?(Array)
307 [false, nil, "No manifest found"],
309 [false, " ", "Invalid manifest: does not end with newline"],
310 [true, ". d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n"],
311 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n"],
312 [true, ". d41d8cd98f00b204e9800998ecf8427e a41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n"], # 2 locators
313 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo/bar.txt\n"],
314 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:.foo.txt\n"],
315 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:.foo\n"],
316 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:...\n"],
317 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:.../.foo./.../bar\n"],
318 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo/...\n"],
319 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo/.../bar\n"],
320 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo/.bar/baz.txt\n"],
321 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo/bar./baz.txt\n"],
322 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 000000000000000000000000000000:0777:foo.txt\n"],
323 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:0:0\n"],
324 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\040\n"],
325 [true, ". 00000000000000000000000000000000+0 0:0:0\n"],
326 [true, ". 00000000000000000000000000000000+0 0:0:d41d8cd98f00b204e9800998ecf8427e+0+Ad41d8cd98f00b204e9800998ecf8427e00000000@ffffffff\n"],
327 [true, ". d41d8cd98f00b204e9800998ecf8427e+0+Ad41d8cd98f00b204e9800998ecf8427e00000000@ffffffff 0:0:empty.txt\n"],
328 [true, "./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 0:0:.\n"],
329 [false, '. d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt',
330 "Invalid manifest: does not end with newline"],
331 [false, "abc d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
332 "invalid stream name \"abc\""],
333 [false, "abc/./foo d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
334 "invalid stream name \"abc/./foo\""],
335 [false, "./abc/../foo d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
336 "invalid stream name \"./abc/../foo\""],
337 [false, "./abc/. d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
338 "invalid stream name \"./abc/.\""],
339 [false, "./abc/.. d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
340 "invalid stream name \"./abc/..\""],
341 [false, "./abc/./foo d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
342 "invalid stream name \"./abc/./foo\""],
343 # non-empty '.'-named file tokens aren't acceptable. Empty ones are used as empty dir placeholders.
344 [false, ". 8cf8463b34caa8ac871a52d5dd7ad1ef+1 0:1:.\n",
345 "invalid file token \"0:1:.\""],
346 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:..\n",
347 "invalid file token \"0:0:..\""],
348 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:./abc.txt\n",
349 "invalid file token \"0:0:./abc.txt\""],
350 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:../abc.txt\n",
351 "invalid file token \"0:0:../abc.txt\""],
352 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt/.\n",
353 "invalid file token \"0:0:abc.txt/.\""],
354 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt/..\n",
355 "invalid file token \"0:0:abc.txt/..\""],
356 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:a/./bc.txt\n",
357 "invalid file token \"0:0:a/./bc.txt\""],
358 [false, ". d41d8cd98f00b204e9800998ecf8427e 0:0:a/../bc.txt\n",
359 "invalid file token \"0:0:a/../bc.txt\""],
360 [false, "./abc/./foo d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt\n",
361 "invalid stream name \"./abc/./foo\""],
362 [false, "d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n",
363 "invalid stream name \"d41d8cd98f00b204e9800998ecf8427e+0\""],
364 [false, ". d41d8cd98f00b204e9800998ecf8427 0:0:abc.txt\n",
365 "invalid locator \"d41d8cd98f00b204e9800998ecf8427\""],
366 [false, ". d41d8cd98f00b204e9800998ecf8427e\n",
367 "Manifest invalid for stream 1: no file tokens"],
368 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n/dir1 d41d8cd98f00b204e9800998ecf842 0:0:abc.txt\n",
369 "Manifest invalid for stream 2: missing or invalid stream name \"/dir1\""],
370 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 d41d8cd98f00b204e9800998ecf842 0:0:abc.txt\n",
371 "Manifest invalid for stream 2: missing or invalid locator \"d41d8cd98f00b204e9800998ecf842\""],
372 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 a41d8cd98f00b204e9800998ecf8427e+0 abc.txt\n",
373 "Manifest invalid for stream 2: invalid file token \"abc.txt\""],
374 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 a41d8cd98f00b204e9800998ecf8427e+0 0:abc.txt\n",
375 "Manifest invalid for stream 2: invalid file token \"0:abc.txt\""],
376 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 a41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt xyz.txt\n",
377 "Manifest invalid for stream 2: invalid file token \"xyz.txt\""],
378 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt d41d8cd98f00b204e9800998ecf8427e+0\n",
379 "Manifest invalid for stream 1: invalid file token \"d41d8cd98f00b204e9800998ecf8427e+0\""],
380 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:\n",
381 "Manifest invalid for stream 1: invalid file token \"0:0:\""],
382 [false, ". d41d8cd98f00b204e9800998ecf8427e+0\n",
383 "Manifest invalid for stream 1: no file tokens"],
384 [false, ". 0:0:foo.txt d41d8cd98f00b204e9800998ecf8427e+0\n",
385 "Manifest invalid for stream 1: missing or invalid locator \"0:0:foo.txt\""],
386 [false, ". 0:0:foo.txt\n",
387 "Manifest invalid for stream 1: missing or invalid locator \"0:0:foo.txt\""],
388 [false, ".\n", "Manifest invalid for stream 1: missing or invalid locator"],
389 [false, ".", "Invalid manifest: does not end with newline"],
390 [false, ". \n", "Manifest invalid for stream 1: missing or invalid locator"],
391 [false, ". \n", "Manifest invalid for stream 1: missing or invalid locator"],
392 [false, " . d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
393 "Manifest invalid for stream 1: missing or invalid stream name"],
394 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt \n",
395 "stream 1: trailing space"],
396 # TAB and other tricky whitespace characters:
397 [false, "\v. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
398 "Manifest invalid for stream 1: missing or invalid stream name \"\\v."],
399 [false, "./foo\vbar d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
400 "Manifest invalid for stream 1: missing or invalid stream name \"./foo\\vbar"],
401 [false, "\t. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
402 "Manifest invalid for stream 1: missing or invalid stream name \"\\t"],
403 [false, ".\td41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
404 "Manifest invalid for stream 1: missing or invalid stream name \".\\t"],
405 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\t\n",
406 "stream 1: invalid file token \"0:0:foo.txt\\t\""],
407 [false, ". d41d8cd98f00b204e9800998ecf8427e+0\t 0:0:foo.txt\n",
408 "stream 1: missing or invalid locator \"d41d8cd98f00b204e9800998ecf8427e+0\\t\""],
409 [false, "./foo\tbar d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
410 "stream 1: missing or invalid stream name \"./foo\\tbar\""],
411 # other whitespace errors:
412 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
413 "Manifest invalid for stream 1: invalid file token \"\""],
414 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n \n",
415 "Manifest invalid for stream 2: missing stream name"],
416 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n\n",
417 "Manifest invalid for stream 2: missing stream name"],
418 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n ",
419 "Invalid manifest: does not end with newline"],
420 [false, "\n. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
421 "Manifest invalid for stream 1: missing stream name"],
422 [false, " \n. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
423 "Manifest invalid for stream 1: missing stream name"],
424 # empty file and stream name components:
425 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:/foo.txt\n",
426 "Manifest invalid for stream 1: invalid file token \"0:0:/foo.txt\""],
427 [false, "./ d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
428 "Manifest invalid for stream 1: missing or invalid stream name \"./\""],
429 [false, ".//foo d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
430 "Manifest invalid for stream 1: missing or invalid stream name \".//foo\""],
431 [false, "./foo/ d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
432 "Manifest invalid for stream 1: missing or invalid stream name \"./foo/\""],
433 [false, "./foo//bar d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
434 "Manifest invalid for stream 1: missing or invalid stream name \"./foo//bar\""],
435 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo//bar.txt\n",
436 "Manifest invalid for stream 1: invalid file token \"0:0:foo//bar.txt\""],
437 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo/\n",
438 "Manifest invalid for stream 1: invalid file token \"0:0:foo/\""],
440 [true, "./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\n"],
441 [false, "./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\\056\n",
442 "Manifest invalid for stream 1: invalid file token \"0:0:\\\\056\\\\056\""],
443 [false, "./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\\056\\057foo\n",
444 "Manifest invalid for stream 1: invalid file token \"0:0:\\\\056\\\\056\\\\057foo\""],
445 [false, "./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 0\\0720\\072foo\n",
446 "Manifest invalid for stream 1: invalid file token \"0\\\\0720\\\\072foo\""],
447 [false, "./empty_dir d41d8cd98f00b204e9800998ecf8427e+0 \\060:\\060:foo\n",
448 "Manifest invalid for stream 1: invalid file token \"\\\\060:\\\\060:foo\""],
449 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\057bar\n"],
450 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\072\n"],
451 [true, ".\\057Data d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n"],
452 [true, "\\056\\057Data d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n"],
453 [true, "./\\134444 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n"],
454 [false, "./\\\\444 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
455 "Manifest invalid for stream 1: missing or invalid stream name \"./\\\\\\\\444\""],
456 [true, "./\\011foo d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n"],
457 [false, "./\\011/.. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
458 "Manifest invalid for stream 1: missing or invalid stream name \"./\\\\011/..\""],
459 [false, ".\\056\\057 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
460 "Manifest invalid for stream 1: missing or invalid stream name \".\\\\056\\\\057\""],
461 [false, ".\\057\\056 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
462 "Manifest invalid for stream 1: missing or invalid stream name \".\\\\057\\\\056\""],
463 [false, ".\\057Data d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\444\n",
464 "Manifest invalid for stream 1: >8-bit encoded chars not allowed on file token \"0:0:foo\\\\444\""],
465 [false, "./\\444 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
466 "Manifest invalid for stream 1: >8-bit encoded chars not allowed on stream token \"./\\\\444\""],
467 [false, "./\tfoo d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
468 "Manifest invalid for stream 1: missing or invalid stream name \"./\\tfoo\""],
469 [false, "./foo\\ d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
470 "Manifest invalid for stream 1: missing or invalid stream name \"./foo\\\\\""],
471 [false, "./foo\\r d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
472 "Manifest invalid for stream 1: missing or invalid stream name \"./foo\\\\r\""],
473 [false, "./foo\\444 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
474 "Manifest invalid for stream 1: >8-bit encoded chars not allowed on stream token \"./foo\\\\444\""],
475 [false, "./foo\\888 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
476 "Manifest invalid for stream 1: missing or invalid stream name \"./foo\\\\888\""],
477 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\\n",
478 "Manifest invalid for stream 1: invalid file token \"0:0:foo\\\\\""],
479 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\r\n",
480 "Manifest invalid for stream 1: invalid file token \"0:0:foo\\\\r\""],
481 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\444\n",
482 "Manifest invalid for stream 1: >8-bit encoded chars not allowed on file token \"0:0:foo\\\\444\""],
483 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\888\n",
484 "Manifest invalid for stream 1: invalid file token \"0:0:foo\\\\888\""],
485 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\\057/bar\n",
486 "Manifest invalid for stream 1: invalid file token \"0:0:foo\\\\057/bar\""],
487 [false, ".\\057/Data d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n",
488 "Manifest invalid for stream 1: missing or invalid stream name \".\\\\057/Data\""],
489 [true, "./Data\\040Folder d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n"],
490 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\057foo/bar\n",
491 "Manifest invalid for stream 1: invalid file token \"0:0:\\\\057foo/bar\""],
492 [true, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\134057foo/bar\n"],
493 [false, ". d41d8cd98f00b204e9800998ecf8427e+0 \\040:\\040:foo.txt\n",
494 "Manifest invalid for stream 1: invalid file token \"\\\\040:\\\\040:foo.txt\""],
495 ].each do |ok, manifest, expected_error=nil|
496 define_method "test_validate manifest #{manifest.inspect}" do
497 assert_equal ok, Keep::Manifest.valid?(manifest)
499 assert Keep::Manifest.validate! manifest
502 Keep::Manifest.validate! manifest
503 rescue ArgumentError => e
506 refute_nil msg, "Expected ArgumentError"
507 assert msg.include?(expected_error), "Did not find expected error message. Expected: #{expected_error}; Actual: #{msg}"