From f29701aeccfc59f521f13b5e2ee73ff15fc99147 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 16 Apr 2009 22:53:54 -0700 Subject: test_upload: ensure StringIO objects are binary Sockets always return binary encoded data, so when StringIO.new(string) is called, that StringIO object inherits the encoding of the initial string it was created with. And yes, Ruby 1.9 still makes me seriously uncomfortable with I/O manipulation since the encoding layer does things behind my back. UNIX is (and should always be) just a bag of bytes! Signed-off-by: Eric Wong --- test/unit/test_upload.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/unit/test_upload.rb b/test/unit/test_upload.rb index 58058f1..c4d6f6f 100644 --- a/test/unit/test_upload.rb +++ b/test/unit/test_upload.rb @@ -18,7 +18,8 @@ class UploadTest < Test::Unit::TestCase @sha1 = Digest::SHA1.new @sha1_app = lambda do |env| input = env['rack.input'] - resp = { :pos => input.pos, :size => input.stat.size } + resp = { :pos => input.pos, :size => input.size, :class => input.class } + @sha1.reset begin loop { @sha1.update(input.sysread(@bs)) } rescue EOFError @@ -193,6 +194,22 @@ class UploadTest < Test::Unit::TestCase resp = `curl -isSfN -T#{tmp.path} http://#@addr:#@port/` assert $?.success?, 'curl ran OK' assert_match(%r!\b#{sha1}\b!, resp) + assert_match(/Tempfile/, resp) + + # small StringIO path + assert(system("dd", "if=#{@random.path}", "of=#{tmp.path}", + "bs=1024", "count=1"), + "dd #@random to #{tmp}") + sha1_re = %r!\b([a-f0-9]{40})\b! + sha1_out = `sha1sum #{tmp.path}` + assert $?.success?, 'sha1sum ran OK' + + assert_match(sha1_re, sha1_out) + sha1 = sha1_re.match(sha1_out)[1] + resp = `curl -isSfN -T#{tmp.path} http://#@addr:#@port/` + assert $?.success?, 'curl ran OK' + assert_match(%r!\b#{sha1}\b!, resp) + assert_match(/StringIO/, resp) end private -- cgit v1.2.3-24-ge0c7