From 0a2cb5093f7fbba370fd9b6caaf308139220b47b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 19 Apr 2011 00:28:08 +0000 Subject: $time_local and $time_utc are locale-independent This doesn't apply to people that use strftime()-formats, but that's a minority. --- test/test_clogger.rb | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'test') 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 -- cgit v1.2.3-24-ge0c7