about summary refs log tree commit homepage
path: root/test/test_fresh.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_fresh.rb')
-rw-r--r--test/test_fresh.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_fresh.rb b/test/test_fresh.rb
index 7585ab0..b619a6a 100644
--- a/test/test_fresh.rb
+++ b/test/test_fresh.rb
@@ -116,4 +116,35 @@ class TestMogFresh < Test::Unit::TestCase
     line = buf.split(/\r?\n/).grep(/\screate_close\s/)[0]
     assert_match(/\bfarewell=goodnight\b/, line)
   end
+
+  def test_get_file_data_range
+    add_host_device_domain
+    client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
+    data = "data"
+    client.store_content("key", "default", data)
+
+    assert_equal data, client.get_file_data("key")
+
+    # ensure offset/length matches IO.copy_stream
+    src = Tempfile.new("tmp")
+    src.write(data)
+    src.flush
+    [ [1,nil], [1,2], [3,1] ].each do |range|
+      dst2 = StringIO.new
+      client.get_file_data("key", dst2, *range)
+
+      src.rewind
+
+      if IO.respond_to?(:copy_stream)
+        # ensure we match IO.copy_stream semantics
+        dst = StringIO.new
+        IO.copy_stream(src, dst, *range)
+        assert_equal dst.string, dst2.string
+        assert_equal dst.string, client.get_file_data("key", nil, *range)
+      end
+
+      assert_equal dst2.string, client.get_file_data("key", nil, *range)
+    end
+    src.close!
+  end
 end