[Groonga-commit] groonga/groonga-log at a961b56 [master] test: simplify

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Nov 9 14:57:21 JST 2017


Kouhei Sutou	2017-11-09 14:57:21 +0900 (Thu, 09 Nov 2017)

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

  Message:
    test: simplify

  Modified files:
    test/test-parser.rb

  Modified: test/test-parser.rb (+31 -56)
===================================================================
--- test/test-parser.rb    2017-11-09 14:54:33 +0900 (126e4c0)
+++ test/test-parser.rb    2017-11-09 14:57:21 +0900 (5e3848e)
@@ -18,62 +18,37 @@
 require "helper"
 
 class ParserTest < Test::Unit::TestCase
-  def test_extract_field
-    raw_statistic = {
-      :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
-      :log_level => :notice,
-      :pid => 29,
-      :message => "spec:2:update:Object:32(type):8",
-    }
-    statistics = parse(<<-LOG)
+  sub_test_case("extract fields") do
+    def test_with_pid
+      raw_statistic = {
+        :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
+        :log_level => :notice,
+        :pid => 29,
+        :message => "spec:2:update:Object:32(type):8",
+      }
+      statistics = parse(<<-LOG)
 2017-07-19 14:09:05.663978|n|29: spec:2:update:Object:32(type):8
-    LOG
-    assert_equal([raw_statistic],
-                 statistics.collect(&:to_h))
-  end
-
-  def test_log_level
-    expected = [
-      :emergency,
-      :alert,
-      :critical,
-      :error,
-      :warning,
-      :notice,
-      :information,
-      :debug,
-      :dump
-    ]
-    statistics = parse(<<-LOG)
-2017-07-19 14:41:05.663978|E|29: emergency
-2017-07-19 14:41:06.663978|A|29: alert
-2017-07-19 14:41:06.663978|C|29: critical
-2017-07-19 14:41:06.663978|e|29: error
-2017-07-19 14:41:06.663978|w|29: warning
-2017-07-19 14:41:06.663978|n|29: notice
-2017-07-19 14:41:06.663978|i|29: information
-2017-07-19 14:41:06.663978|d|29: debug
-2017-07-19 14:41:06.663978|-|29: dump
-    LOG
-    assert_equal(expected,
-                 statistics.collect(&:log_level))
-  end
+      LOG
+      assert_equal([raw_statistic],
+                   statistics.collect(&:to_h))
+    end
 
-  def test_extract_field_no_pid
-    raw_statistic = {
-      :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
-      :log_level => :notice,
-      :pid => nil,
-      :message => "spec:2:update:Object:32(type):8",
-    }
-    statistics = parse(<<-LOG)
+    def test_without_pid
+      raw_statistic = {
+        :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
+        :log_level => :notice,
+        :pid => nil,
+        :message => "spec:2:update:Object:32(type):8",
+      }
+      statistics = parse(<<-LOG)
 2017-07-19 14:09:05.663978|n| spec:2:update:Object:32(type):8
-    LOG
-    assert_equal([raw_statistic],
-                 statistics.collect(&:to_h))
+      LOG
+      assert_equal([raw_statistic],
+                   statistics.collect(&:to_h))
+    end
   end
 
-  def test_log_level_no_pid
+  def test_log_level
     expected = [
       :emergency,
       :alert,
@@ -86,15 +61,15 @@ class ParserTest < Test::Unit::TestCase
       :dump
     ]
     statistics = parse(<<-LOG)
-2017-07-19 14:41:05.663978|E| emergency
+2017-07-19 14:41:05.663978|E|29: emergency
 2017-07-19 14:41:06.663978|A| alert
-2017-07-19 14:41:06.663978|C| critical
+2017-07-19 14:41:06.663978|C|29: critical
 2017-07-19 14:41:06.663978|e| error
-2017-07-19 14:41:06.663978|w| warning
+2017-07-19 14:41:06.663978|w|29: warning
 2017-07-19 14:41:06.663978|n| notice
-2017-07-19 14:41:06.663978|i| information
+2017-07-19 14:41:06.663978|i|29: information
 2017-07-19 14:41:06.663978|d| debug
-2017-07-19 14:41:06.663978|-| dump
+2017-07-19 14:41:06.663978|-|29: dump
     LOG
     assert_equal(expected,
                  statistics.collect(&:log_level))
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171109/c9ac4c5a/attachment-0001.htm 



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