5034: Add Keep::Manifest#files_size to Ruby SDK.
authorBrett Smith <brett@curoverse.com>
Tue, 10 Mar 2015 18:43:29 +0000 (14:43 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 13 Mar 2015 19:14:04 +0000 (15:14 -0400)
sdk/ruby/lib/arvados/keep.rb
sdk/ruby/test/test_keep_manifest.rb

index ede40c3fc2b364f8f886166885fe9e8a59e61e29..e4f62083b0d5568d757d8ae05dc043170e10f6ca 100644 (file)
@@ -191,6 +191,11 @@ module Keep
       seen_files.size
     end
 
+    def files_size
+      # Return the total size of all files in this manifest.
+      files.reduce(0) { |total, (_, _, size)| total + size }
+    end
+
     def exact_file_count?(want_count)
       files_count(want_count + 1) == want_count
     end
index 2ad0941e04b681485c7623cd316b5d4cf99de658..f1f1a530ceddbf35a9d5cd3066acc180eb4f254e 100644 (file)
@@ -58,6 +58,10 @@ class ManifestTest < Minitest::Test
     assert_equal(0, Keep::Manifest.new("").files_count)
   end
 
+  def test_empty_files_size
+    assert_equal(0, Keep::Manifest.new("").files_size)
+  end
+
   def test_empty_has_file?
     refute(Keep::Manifest.new("").has_file?(""))
   end
@@ -151,6 +155,15 @@ class ManifestTest < Minitest::Test
     refute(manifest.exact_file_count?(6), "+1 file count true")
   end
 
+  def test_files_size_multiblock
+    assert_equal(22, Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST).files_size)
+  end
+
+  def test_files_size_with_skipped_overlapping_data
+    manifest = Keep::Manifest.new(". #{random_block(9)} 3:3:f1 5:3:f2\n")
+    assert_equal(6, manifest.files_size)
+  end
+
   def test_has_file
     manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
     assert(manifest.has_file?("./repfile"), "one-arg repfile not found")