5176: Fix broken fixtures, add tests.
authorTom Clegg <tom@curoverse.com>
Mon, 9 Feb 2015 22:34:41 +0000 (17:34 -0500)
committerTom Clegg <tom@curoverse.com>
Mon, 9 Feb 2015 22:37:54 +0000 (17:37 -0500)
sdk/ruby/lib/arvados/keep.rb
sdk/ruby/test/test_keep_manifest.rb
services/api/test/fixtures/collections.yml

index 25a6ae1c17b3a4113b0c36d09cc742041b3a3aa2..ede40c3fc2b364f8f886166885fe9e8a59e61e29 100644 (file)
@@ -138,6 +138,9 @@ module Keep
 
     def split_file_token token
       start_pos, filesize, filename = token.split(':', 3)
+      if filename.nil?
+        raise ArgumentError.new "Invalid file token '#{token}'"
+      end
       [start_pos.to_i, filesize.to_i, unescape(filename)]
     end
 
index 50a3d36210007ba7accb307258aae62df37ce0ab..8ad8134592984dabd203d822d42b0e8696bb5a83 100644 (file)
@@ -1,5 +1,6 @@
 require "minitest/autorun"
 require "arvados/keep"
+require "yaml"
 
 def random_block(size=nil)
   sprintf("%032x+%d", rand(16 ** 32), size || rand(64 * 1024 * 1024))
@@ -182,4 +183,40 @@ class ManifestTest < Minitest::Test
     refute(manifest.has_file?("a\\040b\\040c"), "one-arg unescaped found")
     refute(manifest.has_file?(".", "a\\040b\\040c"), "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
+
+  @@fixtures = nil
+  def fixtures name
+    return @@fixtures if @@fixtures
+    path = File.expand_path("../../../../services/api/test/fixtures/#{name}.yml",
+                            __FILE__)
+    file = IO.read(path)
+    trim_index = file.index('# Test Helper trims the rest of the file')
+    file = file[0, trim_index] if trim_index
+    @@fixtures = YAML.load(file)
+  end
 end
index 841917864f24e058fa36bf615ec7acaca0739f90..98347167a7f138faaa44bf433e44258ade98b6db 100644 (file)
@@ -60,7 +60,7 @@ baz_file:
 
 w_a_z_file:
   uuid: zzzzz-4zz18-25k12570yk134b3
-  portable_data_hash: 8706aadd12a0ebc07d74cae88762ba9e
+  portable_data_hash: 8706aadd12a0ebc07d74cae88762ba9e+56
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   created_at: 2015-02-09T10:53:38Z
   modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
@@ -359,12 +359,12 @@ collection_with_no_name_in_aproject:
 
 collection_to_search_for_in_aproject:
   uuid: zzzzz-4zz18-abcd6fx123409f7
-  portable_data_hash: 5bd9c1ad0bc8c7f34be170a7b7b39089+45
+  portable_data_hash: 1f4b0bc7583c2a7f9102c395f4ffc5e3+45
   owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
   created_at: 2014-04-21 15:37:48 -0400
   modified_at: 2014-04-21 15:37:48 -0400
   updated_at: 2014-04-21 15:37:48 -0400
-  manifest_text: ". juku76584cc2f85cedef654fjyhtgimh+3 0:3:foo\n"
+  manifest_text: ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo\n"
   name: "zzzzz-4zz18-abcd6fx123409f7 used to search with any"
 
 upload_sandbox: