about summary refs log tree commit homepage
path: root/test/test_clogger.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_clogger.rb')
-rw-r--r--test/test_clogger.rb45
1 files changed, 37 insertions, 8 deletions
diff --git a/test/test_clogger.rb b/test/test_clogger.rb
index 1a555ba..9440d74 100644
--- a/test/test_clogger.rb
+++ b/test/test_clogger.rb
@@ -18,6 +18,8 @@ class TestClogger < Test::Unit::TestCase
   include Clogger::Format
 
   def setup
+    @tz = ENV["TZ"]
+    @nginx_fmt = "%d/%b/%Y:%H:%M:%S %z"
     @req = {
       "REQUEST_METHOD" => "GET",
       "HTTP_VERSION" => "HTTP/1.0",
@@ -30,6 +32,10 @@ class TestClogger < Test::Unit::TestCase
     }
   end
 
+  def teardown
+    ENV["TZ"] = @tz
+  end
+
   def test_init_basic
     Clogger.new(lambda { |env| [ 0, {}, [] ] })
   end
@@ -162,13 +168,12 @@ class TestClogger < Test::Unit::TestCase
         '$env{rack.url_scheme}' \
         "\n")
     }
-    longest_day = Time.at(26265600).strftime('%d/%b/%Y:%H:%M:%S %z')
     expect = [
       [ Clogger::OP_REQUEST, "REMOTE_ADDR" ],
       [ Clogger::OP_LITERAL, " - " ],
       [ Clogger::OP_REQUEST, "REMOTE_USER" ],
       [ Clogger::OP_LITERAL, " [" ],
-      [ Clogger::OP_TIME_LOCAL, '%d/%b/%Y:%H:%M:%S %z', longest_day ],
+      [ Clogger::OP_SPECIAL, Clogger::SPECIAL_VARS[:time_local] ],
       [ Clogger::OP_LITERAL, "] \"" ],
       [ Clogger::OP_SPECIAL, Clogger::SPECIAL_VARS[:request] ],
       [ Clogger::OP_LITERAL, "\" "],
@@ -714,7 +719,6 @@ class TestClogger < Test::Unit::TestCase
   end
 
   def test_time_iso8601_pst8pdt
-    orig = ENV["TZ"]
     ENV["TZ"] = "PST8PDT"
     s = []
     app = lambda { |env| [200, [], [] ] }
@@ -722,12 +726,9 @@ class TestClogger < Test::Unit::TestCase
     status, headers, body = cl.call(@req)
     t = Time.parse(s[0])
     assert_equal t.iso8601, s[0].strip
-    ensure
-      ENV["TZ"] = orig
   end
 
   def test_time_iso8601_utc
-    orig = ENV["TZ"]
     ENV["TZ"] = "UTC"
     s = []
     app = lambda { |env| [200, [], [] ] }
@@ -735,8 +736,36 @@ class TestClogger < Test::Unit::TestCase
     status, headers, body = cl.call(@req)
     t = Time.parse(s[0])
     assert_equal t.iso8601, s[0].strip
-    ensure
-      ENV["TZ"] = orig
+  end
+
+  def test_time_local
+    s = []
+    app = lambda { |env| [200, [], [] ] }
+    cl = Clogger.new(app, :logger => s, :format => "$time_local")
+    status, headers, body = cl.call(@req)
+    t = DateTime.strptime(s[0].strip, @nginx_fmt)
+    assert_equal t.strftime(@nginx_fmt), s[0].strip
+  end
+
+  def test_time_local_pst8pdt
+    orig = ENV["TZ"]
+    ENV["TZ"] = "PST8PDT"
+    s = []
+    app = lambda { |env| [200, [], [] ] }
+    cl = Clogger.new(app, :logger => s, :format => "$time_local")
+    status, headers, body = cl.call(@req)
+    t = DateTime.strptime(s[0].strip, @nginx_fmt)
+    assert_equal t.strftime(@nginx_fmt), s[0].strip
+  end
+
+  def test_time_local_utc
+    ENV["TZ"] = "UTC"
+    s = []
+    app = lambda { |env| [200, [], [] ] }
+    cl = Clogger.new(app, :logger => s, :format => "$time_local")
+    status, headers, body = cl.call(@req)
+    t = DateTime.strptime(s[0].strip, @nginx_fmt)
+    assert_equal t.strftime(@nginx_fmt), s[0].strip
   end
 
   def test_method_missing