about summary refs log tree commit homepage
path: root/test/http_chunked_put.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-01-31 08:23:36 +0000
committerEric Wong <normalperson@yhbt.net>2012-01-31 16:32:47 -0800
commitaeaa2a335aa9bb3a9ce2f5767e439f45011ab765 (patch)
tree5f82fd46992603bb0a08a31a961b69da9ea1c946 /test/http_chunked_put.rb
parent73b7635440bd4a3d44e04c5c220bf7f1ccc2b481 (diff)
downloadcmogstored-aeaa2a335aa9bb3a9ce2f5767e439f45011ab765.tar.gz
In case MogileFS clients rely on these fields, we're
closer to being a "real" HTTP server.
Diffstat (limited to 'test/http_chunked_put.rb')
-rw-r--r--test/http_chunked_put.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/test/http_chunked_put.rb b/test/http_chunked_put.rb
index c4f9635..523190e 100644
--- a/test/http_chunked_put.rb
+++ b/test/http_chunked_put.rb
@@ -12,6 +12,14 @@ require 'stringio'
 $stderr.sync = $stdout.sync = Thread.abort_on_exception = true
 
 class TestHTTPChunkedPut < Test::Unit::TestCase
+  EPOCH = "Thu, 01 Jan 1970 00:00:00 GMT"
+
+  def replace_dates!(header)
+    rv = header.gsub!(/: \w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n/,
+                      ": #{EPOCH}\r\n")
+    assert(rv, header)
+  end
+
   def setup
     @tmpdir = Dir.mktmpdir('cmogstored-httpchunkedput-test')
     @to_close = []
@@ -76,6 +84,8 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
   def test_edge_finder
     expect = "HTTP/1.1 200 OK\r\n" \
              "Status: 200 OK\r\n" \
+             "Date: #{EPOCH}\r\n" \
+             "Last-Modified: #{EPOCH}\r\n" \
              "Content-Length: 5\r\n" \
              "Content-Type: application/octet-stream\r\n" \
              "Connection: close\r\n\r\nabcde"
@@ -98,7 +108,9 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
         if suf =~ /GET\z/
           sleep 0.01
           @client.write " /zz HTTP/1.0\r\n\r\n"
-          assert_equal expect, @client.read(expect.size), "i=#{i}"
+          got = @client.read(expect.size)
+          replace_dates!(got)
+          assert_equal expect, got, "i=#{i}"
         end
         @client.close
         @client = TCPSocket.new(@host, @port)
@@ -109,10 +121,12 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
   def check_abcde(msg=nil)
     expect = "HTTP/1.1 201 Created\r\n" \
       "Status: 201 Created\r\n" \
+      "Date: #{EPOCH}\r\n" \
       "Content-Length: 0\r\n" \
       "Content-Type: text/plain\r\n" \
       "Connection: keep-alive\r\n\r\n"
     resp = @client.readpartial(666)
+    replace_dates!(resp)
     assert_equal expect, resp, msg
     assert_equal "abcde", IO.read("#@tmpdir/zz")
   end
@@ -200,10 +214,13 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
     @client.write(moar)
     expect = "HTTP/1.1 200 OK\r\n" \
              "Status: 200 OK\r\n" \
+             "Date: #{EPOCH}\r\n" \
+             "Last-Modified: #{EPOCH}\r\n" \
              "Content-Length: 5\r\n" \
              "Content-Type: application/octet-stream\r\n" \
              "Connection: keep-alive\r\n\r\nabcde"
     resp = @client.read(expect.size)
+    replace_dates!(resp)
     assert_equal expect, resp
   end
 
@@ -222,10 +239,13 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
     @client.write(more)
     expect = "HTTP/1.1 200 OK\r\n" \
              "Status: 200 OK\r\n" \
+             "Date: #{EPOCH}\r\n" \
+             "Last-Modified: #{EPOCH}\r\n" \
              "Content-Length: 5\r\n" \
              "Content-Type: application/octet-stream\r\n" \
              "Connection: keep-alive\r\n\r\nabcde"
     resp = @client.read(expect.size)
+    replace_dates!(resp)
     assert_equal expect, resp
   end
 
@@ -247,10 +267,13 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
     @client.write(moar)
     expect = "HTTP/1.1 200 OK\r\n" \
              "Status: 200 OK\r\n" \
+             "Date: #{EPOCH}\r\n" \
+             "Last-Modified: #{EPOCH}\r\n" \
              "Content-Length: 5\r\n" \
              "Content-Type: application/octet-stream\r\n" \
              "Connection: keep-alive\r\n\r\nabcde"
     resp = @client.read(expect.size)
+    replace_dates!(resp)
     assert_equal expect, resp
   end
 
@@ -262,11 +285,13 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
     @client.write(req)
     expect = "HTTP/1.1 201 Created\r\n" \
       "Status: 201 Created\r\n" \
+      "Date: #{EPOCH}\r\n" \
       "Content-Length: 0\r\n" \
       "Content-Type: text/plain\r\n" \
       "Connection: keep-alive\r\n" \
       "\r\n"
     resp = @client.readpartial(666)
+    replace_dates!(resp)
     assert_equal expect, resp
     assert_equal "", IO.read("#@tmpdir/zero")
     assert_nil IO.select([@client], nil, nil, 0.1)
@@ -283,10 +308,12 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
     @client.write(req)
     expect = "HTTP/1.1 201 Created\r\n" \
       "Status: 201 Created\r\n" \
+      "Date: #{EPOCH}\r\n" \
       "Content-Length: 0\r\n" \
       "Content-Type: text/plain\r\n" \
       "Connection: keep-alive\r\n\r\n"
     resp = @client.read(expect.size * 2)
+    replace_dates!(resp)
     assert_equal(expect * 2, resp)
     assert_equal "abcd0", IO.read("#@tmpdir/0")
     assert_equal "abcd1", IO.read("#@tmpdir/1")
@@ -309,10 +336,12 @@ class TestHTTPChunkedPut < Test::Unit::TestCase
 
     expect = "HTTP/1.1 201 Created\r\n" \
       "Status: 201 Created\r\n" \
+      "Date: #{EPOCH}\r\n" \
       "Content-Length: 0\r\n" \
       "Content-Type: text/plain\r\n" \
       "Connection: keep-alive\r\n\r\n"
     resp = @client.read(expect.size * 2)
+    replace_dates!(resp)
     assert_equal(expect * 2, resp)
     assert_equal "abcd0", IO.read("#@tmpdir/0")
     assert_equal "abcd1", IO.read("#@tmpdir/1")