From c0b3faa0922d895e6aafa9802df69649b1977eae Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Dec 2012 20:20:00 +0000 Subject: test for size mismatch errors with IO.copy_stream 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_fresh.rb b/test/test_fresh.rb index b619a6a..706783e 100644 --- a/test/test_fresh.rb +++ b/test/test_fresh.rb @@ -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 -- cgit v1.2.3-24-ge0c7