about summary refs log tree commit homepage
path: root/test/unit/test_tee_input.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-08-09 03:02:54 -0700
committerEric Wong <normalperson@yhbt.net>2009-08-09 03:11:34 -0700
commit81026ea66279695206ea53287427c05281662572 (patch)
tree14909515a565f77647e233de6c1b159d85c8a97e /test/unit/test_tee_input.rb
parent5b9d3e4a5ea5b5832f2b91fb9d6288c59b65a199 (diff)
downloadunicorn-81026ea66279695206ea53287427c05281662572.tar.gz
This should be more robust, faster and easier to deal
with than the ugly proof-of-concept regexp-based ones.
Diffstat (limited to 'test/unit/test_tee_input.rb')
-rw-r--r--test/unit/test_tee_input.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb
index a6c61e6..3a6c998 100644
--- a/test/unit/test_tee_input.rb
+++ b/test/unit/test_tee_input.rb
@@ -26,7 +26,8 @@ class TestTeeInput < Test::Unit::TestCase
   end
 
   def test_gets_long
-    ti = Unicorn::TeeInput.new(@rd, nil, "hello")
+    init_parser("hello", 5 + (4096 * 4 * 3) + "#$/foo#$/".size)
+    ti = Unicorn::TeeInput.new(@rd)
     status = line = nil
     pid = fork {
       @rd.close
@@ -46,7 +47,8 @@ class TestTeeInput < Test::Unit::TestCase
   end
 
   def test_gets_short
-    ti = Unicorn::TeeInput.new(@rd, nil, "hello")
+    init_parser("hello", 5 + "#$/foo".size)
+    ti = Unicorn::TeeInput.new(@rd)
     status = line = nil
     pid = fork {
       @rd.close
@@ -63,4 +65,19 @@ class TestTeeInput < Test::Unit::TestCase
     assert status.success?
   end
 
+private
+
+  def init_parser(body, size = nil)
+    @parser = Unicorn::TeeInput::PARSER
+    @parser.reset
+    body = body.to_s.freeze
+    buf = "POST / HTTP/1.1\r\n" \
+          "Host: localhost\r\n" \
+          "Content-Length: #{size || body.size}\r\n" \
+          "\r\n#{body}"
+    buf = Unicorn::TeeInput::RAW.replace(buf)
+    assert_equal @env, @parser.headers(@env, buf)
+    assert_equal body, buf
+  end
+
 end