test for size mismatch errors with IO.copy_stream
authorEric Wong <normalperson@yhbt.net>
Mon, 24 Dec 2012 20:20:00 +0000 (24 20:20 +0000)
committerEric Wong <normalperson@yhbt.net>
Mon, 24 Dec 2012 20:23:12 +0000 (24 20:23 +0000)
IO.copy_stream does not raise EOFError when specified
copy length is less than input size.  Thus we must rely
on the MogileFS tracker to validate the input size.

test/test_fresh.rb

index b619a6a..706783e 100644 (file)
@@ -147,4 +147,22 @@ class TestMogFresh < Test::Unit::TestCase
     end
     src.close!
   end
+
+  def test_new_file_copy_stream_known_length
+    add_host_device_domain
+    opts = { :content_length => 666 }
+    input = StringIO.new("short")
+    client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
+    assert_raises(MogileFS::SizeMismatchError) do
+      client.new_file("copy_stream", opts) do |io|
+        IO.copy_stream(input, io)
+      end
+    end
+
+    assert_raises(MogileFS::SizeMismatchError) do
+      client.new_file("copy_stream", opts) do |io|
+        IO.copy_stream(input, io, 666)
+      end
+    end
+  end if IO.respond_to?(:copy_stream)
 end