diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-16 22:53:54 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-16 22:57:12 -0700 |
commit | f29701aeccfc59f521f13b5e2ee73ff15fc99147 (patch) | |
tree | c96187a363e66aa330a9829d210204912860af7f | |
parent | f2e90a9f15efda1abc87cde00bb341fdf3368985 (diff) | |
download | unicorn-f29701aeccfc59f521f13b5e2ee73ff15fc99147.tar.gz |
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 <normalperson@yhbt.net>
-rw-r--r-- | test/unit/test_upload.rb | 19 |
1 files changed, 18 insertions, 1 deletions
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 |