null+****@clear*****
null+****@clear*****
2011年 5月 31日 (火) 18:49:55 JST
Kouhei Sutou 2011-05-31 09:49:55 +0000 (Tue, 31 May 2011)
New Revision: 86ae988dde5e215ff902b57c24f62bcb262a6dbc
Log:
[query-log][analyzer][test] add a test for query log analyzer.
Added files:
test/unit/tools/test-query-log-analyzer.rb
Modified files:
test/unit/run-test.rb
tools/groonga-query-log-analyzer.rb
Modified: test/unit/run-test.rb (+1 -0)
===================================================================
--- test/unit/run-test.rb 2011-05-31 09:32:42 +0000 (6c3abce)
+++ test/unit/run-test.rb 2011-05-31 09:49:55 +0000 (5b01ba4)
@@ -63,6 +63,7 @@ $LOAD_PATH.unshift(File.join(json_dir, "lib"))
$LOAD_PATH.unshift(File.join(base_dir, "lib", "ruby"))
+$LOAD_PATH.unshift(File.expand_path(File.join(base_dir, "..", "..", "tools")))
require 'groonga-test-utils'
require 'groonga-http-test-utils'
Added: test/unit/tools/test-query-log-analyzer.rb (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/tools/test-query-log-analyzer.rb 2011-05-31 09:49:55 +0000 (58df751)
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2009-2011 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+require "groonga-query-log-analyzer"
+
+module QueryLogAalyzerTest
+ class CommandParseTest < Test::Unit::TestCase
+ def test_simple
+ select = parse("/d/select.json?table=Users&filter=age<=30")
+ assert_equal(command("select",
+ "table" => "Users",
+ "filter" => "age<=30",
+ "output_type" => "json"),
+ select)
+ end
+
+ private
+ def command(name, parameters)
+ GroongaQueryLogAnaylzer::Command.new(name, parameters)
+ end
+
+ def parse(command_path)
+ GroongaQueryLogAnaylzer::Command.parse(command_path)
+ end
+ end
+end
Modified: tools/groonga-query-log-analyzer.rb (+10 -1)
===================================================================
--- tools/groonga-query-log-analyzer.rb 2011-05-31 09:32:42 +0000 (8268800)
+++ tools/groonga-query-log-analyzer.rb 2011-05-31 09:49:55 +0000 (41fb87c)
@@ -69,7 +69,10 @@ class GroongaQueryLogAnaylzer
key, value = parameter_string.split(/\=/, 2)
parameters[key] = CGI.unescape(value)
end
- new(name.gsub(/\A\/d\//, ''), parameters)
+ name = name.gsub(/\A\/d\//, '')
+ name, output_type = name.split(/\./, 2)
+ parameters["output_type"] = output_type if output_type
+ new(name, parameters)
end
end
@@ -78,6 +81,12 @@ class GroongaQueryLogAnaylzer
@name = name
@parameters = parameters
end
+
+ def ==(other)
+ other.is_a?(self.class) and
+ @name == other.name and
+ @parameters == other.parameters
+ end
end
class SelectCommand < Command