[Groonga-commit] groonga/groonga-log at 5db9dd8 [master] Fill timestamp in to_h

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Sep 27 16:48:06 JST 2017


Kouhei Sutou	2017-09-27 16:48:06 +0900 (Wed, 27 Sep 2017)

  New Revision: 5db9dd86adfb43a9dabbb25a2887a55b0f70a37c
  https://github.com/groonga/groonga-log/commit/5db9dd86adfb43a9dabbb25a2887a55b0f70a37c

  Message:
    Fill timestamp in to_h

  Modified files:
    lib/groonga-log/statistic.rb
    test/test-parser.rb

  Modified: lib/groonga-log/statistic.rb (+6 -0)
===================================================================
--- lib/groonga-log/statistic.rb    2017-09-27 16:45:13 +0900 (36c9d33)
+++ lib/groonga-log/statistic.rb    2017-09-27 16:48:06 +0900 (d8ac51a)
@@ -29,5 +29,11 @@ module GroongaLog
     def timestamp
       super || Time.local(year, month, day, hour, minute, second, micro_second)
     end
+
+    def to_h
+      hash = super
+      hash[:timestamp] ||= timestamp
+      hash
+    end
   end
 end

  Modified: test/test-parser.rb (+3 -18)
===================================================================
--- test/test-parser.rb    2017-09-27 16:45:13 +0900 (eb69754)
+++ test/test-parser.rb    2017-09-27 16:48:06 +0900 (f7db9d0)
@@ -18,16 +18,9 @@
 require "helper"
 
 class ParserTest < Test::Unit::TestCase
-  def create_statistic(args)
-    statistic = GroongaLog::Statistic.new
-    args.each do |key, value|
-      statistic[key] = value
-    end
-    statistic
-  end
-
   def test_extract_field
     raw_statistic = {
+      :timestamp => Time.local(2017, 7, 19, 14, 41, 5, 663978),
       :year => 2017,
       :month => 7,
       :day => 19,
@@ -39,19 +32,11 @@ class ParserTest < Test::Unit::TestCase
       :context_id => "18c61700",
       :message => "spec:2:update:Object:32(type):8",
     }
-    expected = [create_statistic(raw_statistic)]
-    statistics = parse(<<-LOG)
-2017-07-19 14:41:05.663978|n|18c61700|spec:2:update:Object:32(type):8
-    LOG
-    assert_equal(expected, statistics)
-  end
-
-  def test_timestamp
     statistics = parse(<<-LOG)
 2017-07-19 14:41:05.663978|n|18c61700|spec:2:update:Object:32(type):8
     LOG
-    assert_equal([Time.local(2017, 7, 19, 14, 41, 5, 663978)],
-                 statistics.collect(&:timestamp))
+    assert_equal([raw_statistic],
+                 statistics.collect(&:to_h))
   end
 
   def test_log_level
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170927/5d010bbf/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index