Kentaro Hayashi
null+****@clear*****
Tue Sep 26 16:37:15 JST 2017
Kentaro Hayashi 2017-09-26 16:37:15 +0900 (Tue, 26 Sep 2017) New Revision: d8e6e02d1921e4acb5ea7c6986825d8c27ea43b6 https://github.com/groonga/groonga-log/commit/d8e6e02d1921e4acb5ea7c6986825d8c27ea43b6 Merged ab8830c: Merge pull request #4 from kenhys/extract-parser-from-f-p-g-l Message: Add test case for GroongaLog::Parser Added files: test/helper.rb test/run-test.rb test/test-parser.rb Added: test/helper.rb (+17 -0) 100644 =================================================================== --- /dev/null +++ test/helper.rb 2017-09-26 16:37:15 +0900 (af4cfd7) @@ -0,0 +1,17 @@ +# Copyright (C) 2017 Kentaro Hayashi <hayashi �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require "groonga-log" Added: test/run-test.rb (+45 -0) 100755 =================================================================== --- /dev/null +++ test/run-test.rb 2017-09-26 16:37:15 +0900 (bb088b9) @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby +# +# Copyright (C) 2012-2013 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +$VERBOSE = true + +require "pathname" + +base_dir = Pathname.new(__FILE__).dirname.parent.expand_path +top_dir = base_dir.parent + +lib_dir = base_dir + "lib" +test_dir = base_dir + "test" + +require "test-unit" +require "test/unit/notify" + +Test::Unit::Priority.enable + +$LOAD_PATH.unshift(lib_dir.to_s) + +$LOAD_PATH.unshift(test_dir.to_s) +require "helper" + +Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file| + require file.sub(/\.rb\z/, '') +end + +ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000" + +exit Test::Unit::AutoRunner.run Added: test/test-parser.rb (+75 -0) 100644 =================================================================== --- /dev/null +++ test/test-parser.rb 2017-09-26 16:37:15 +0900 (d043985) @@ -0,0 +1,75 @@ +# Copyright (C) 2017 Yasuhiro Horimoto <horimoto �� clear-code.com> +# Copyright (C) 2017 Kentaro Hayashi <hayashi �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require "helper" + +class ParserTest < Test::Unit::TestCase + def test_extract_field + expected = [{ + :timestamp => Time.local(2017, 7, 19, 14, 41, 5, 663978), + :year => 2017, + :month => 7, + :day => 19, + :hour => 14, + :minutes => 41, + :seconds => 5, + :micro_seconds => 663978, + :log_level => :notice, + :context_id => "18c61700", + :message => "spec:2:update:Object:32(type):8", + }] + 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_log_level + expected = [ + :emergency, + :alert, + :critical, + :error, + :warning, + :notice, + :information, + :debug, + :dump + ] + statistics = parse(<<-LOG) +2017-07-19 14:41:05.663978|E|18c61700|emergency +2017-07-19 14:41:06.663978|A|18c61700|alert +2017-07-19 14:41:06.663978|C|18c61700|critical +2017-07-19 14:41:06.663978|e|18c61700|error +2017-07-19 14:41:06.663978|w|18c61700|warning +2017-07-19 14:41:06.663978|n|18c61700|notice +2017-07-19 14:41:06.663978|i|18c61700|information +2017-07-19 14:41:06.663978|d|18c61700|debug +2017-07-19 14:41:06.663978|-|18c61700|dump + LOG + log_levels = statistics.collect do |statistic| + statistic[:log_level] + end + assert_equal(expected, log_levels) + end + + private + def parse(log) + parser = GroongaLog::Parser.new + parser.parse(log).to_a + end +end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170926/d84fc71e/attachment-0001.htm