From 5bbd75f2bf63d17ef84c7cd156faca278d80bb5b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Apr 2009 03:47:46 -0700 Subject: test_upload: still uncomfortable with 1.9 IO encoding... It seems most applications use buffered IO#read instead of IO#sysread. So make sure our encoding is set correctly for buffered IO#read applications, too. --- test/unit/test_upload.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/unit/test_upload.rb b/test/unit/test_upload.rb index b06dfdb..9ef3ed7 100644 --- a/test/unit/test_upload.rb +++ b/test/unit/test_upload.rb @@ -19,12 +19,28 @@ class UploadTest < Test::Unit::TestCase @sha1_app = lambda do |env| input = env['rack.input'] resp = { :pos => input.pos, :size => input.size, :class => input.class } + + # sysread @sha1.reset begin loop { @sha1.update(input.sysread(@bs)) } rescue EOFError end resp[:sha1] = @sha1.hexdigest + + # read + input.sysseek(0) if input.respond_to?(:sysseek) + input.rewind + @sha1.reset + loop { + buf = input.read(@bs) or break + @sha1.update(buf) + } + + if resp[:sha1] == @sha1.hexdigest + resp[:sysread_read_byte_match] = true + end + [ 200, @hdr.merge({'X-Resp' => resp.inspect}), [] ] end end @@ -218,6 +234,7 @@ class UploadTest < Test::Unit::TestCase assert $?.success?, 'curl ran OK' assert_match(%r!\b#{sha1}\b!, resp) assert_match(/Tempfile/, resp) + assert_match(/sysread_read_byte_match/, resp) # small StringIO path assert(system("dd", "if=#{@random.path}", "of=#{tmp.path}", @@ -233,6 +250,7 @@ class UploadTest < Test::Unit::TestCase assert $?.success?, 'curl ran OK' assert_match(%r!\b#{sha1}\b!, resp) assert_match(/StringIO/, resp) + assert_match(/sysread_read_byte_match/, resp) end private -- cgit v1.2.3-24-ge0c7