From: Eric Wong Date: Mon, 24 Dec 2012 20:20:00 +0000 (+0000) Subject: test for size mismatch errors with IO.copy_stream X-Git-Tag: v3.6.0~5 X-Git-Url: https://repo.or.cz/w/ruby-mogilefs-client.git/commitdiff_plain/c0b3faa0922d895e6aafa9802df69649b1977eae 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. --- 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