summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-27 03:47:46 -0700
committerEric Wong <normalperson@yhbt.net>2009-05-22 01:54:20 -0700
commit5bbd75f2bf63d17ef84c7cd156faca278d80bb5b (patch)
tree25d17b03465149252fa1074c9c3a7db8e2ce164f
parent1de33f9cdc735588e8dee100e64e68c68b990830 (diff)
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.
-rw-r--r--test/unit/test_upload.rb18
1 files changed, 18 insertions, 0 deletions
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