groonga-query-log 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +7 -0
- data/doc/text/run-regression-test.md +24 -0
- data/lib/groonga/query-log/command/format-regression-test-logs.rb +38 -22
- data/lib/groonga/query-log/version.rb +1 -1
- data/test/command/test-format-regression-test-logs.rb +88 -0
- data/test/fixtures/regression-test-logs/command-format.log +3 -0
- data/test/fixtures/regression-test-logs/url-format.log +3 -0
- data/test/helper.rb +30 -0
- data/test/run-test.rb +1 -1
- metadata +10 -6
- data/test/command/test-select.rb +0 -162
- data/test/groonga-query-log-test-utils.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb5671eabd420c831e66da0a0ecb8c76788e6b7a
|
4
|
+
data.tar.gz: 635098f7db2bb18cea3a3f5626c85ef5a924c643
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb4900d64685c1d444756c1fcc10aa02300ae5c198dd8d8998c979158e06d31be0b45c48da74b6152a38408a78bd2ffad1fa961fd70fe94952c30b02049abb1a
|
7
|
+
data.tar.gz: 27d9c1647ce24ec881e51fbf774dab77f9fd718cb8c7e81f9d1c017a4e6332b9fbff7884266a4efdfa38624376a7955635ea1047b9d617bc4ad413853cdb40a9
|
data/doc/text/news.md
CHANGED
@@ -158,6 +158,30 @@ directory. Test result log file name is the same as input query log
|
|
158
158
|
file name. If query log file is `query-logs/query-20140508.log`, test
|
159
159
|
result log file is `results/query-20140508.log`.
|
160
160
|
|
161
|
+
### Confirm
|
162
|
+
|
163
|
+
You can show details of different between the current Groonga and the
|
164
|
+
new Groonga by `groonga-query-log-format-regression-test-logs` command:
|
165
|
+
|
166
|
+
% groonga-query-log-format-regression-test-logs results/*.log
|
167
|
+
|
168
|
+
Here is a sample output:
|
169
|
+
|
170
|
+
select Logs
|
171
|
+
Name: select
|
172
|
+
Arguments:
|
173
|
+
table: Logs
|
174
|
+
--- old
|
175
|
+
+++ new
|
176
|
+
@@ -1,4 +1,5 @@
|
177
|
+
-[[[2],
|
178
|
+
+[[[3],
|
179
|
+
[["_id", "UInt32"], ["message", "Text"]],
|
180
|
+
[1, "log message1"],
|
181
|
+
- [2, "log message2"]]]
|
182
|
+
+ [2, "log message2"],
|
183
|
+
+ [3, "log message3"]]]
|
184
|
+
|
161
185
|
## Advanced usage
|
162
186
|
|
163
187
|
There are some advanced usages. This section describes about them.
|
@@ -21,6 +21,8 @@ require "pp"
|
|
21
21
|
require "optparse"
|
22
22
|
require "json"
|
23
23
|
|
24
|
+
require "groonga/command/parser"
|
25
|
+
|
24
26
|
require "groonga/query-log/version"
|
25
27
|
|
26
28
|
module Groonga
|
@@ -60,8 +62,8 @@ module Groonga
|
|
60
62
|
private
|
61
63
|
def format_log(input, path)
|
62
64
|
command = nil
|
63
|
-
|
64
|
-
|
65
|
+
response_old = nil
|
66
|
+
response_new = nil
|
65
67
|
|
66
68
|
input.each_line do |line|
|
67
69
|
unless line.valid_encoding?
|
@@ -73,32 +75,32 @@ module Groonga
|
|
73
75
|
when /\Acommand: /
|
74
76
|
command = $POSTMATCH.chomp
|
75
77
|
when /\Aresponse1: /
|
76
|
-
|
78
|
+
response_old = $POSTMATCH.chomp
|
77
79
|
when /\Aresponse2: /
|
78
|
-
|
79
|
-
next unless valid_entry?(command,
|
80
|
-
report_diff(command,
|
80
|
+
response_new = $POSTMATCH.chomp
|
81
|
+
next unless valid_entry?(command, response_old, response_new)
|
82
|
+
report_diff(command, response_old, response_new)
|
81
83
|
end
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
|
-
def valid_entry?(command,
|
87
|
+
def valid_entry?(command, response_old, response_new)
|
86
88
|
valid = true
|
87
89
|
|
88
90
|
begin
|
89
|
-
JSON.parse(
|
91
|
+
JSON.parse(response_old)
|
90
92
|
rescue JSON::ParserError
|
91
93
|
puts(command)
|
92
|
-
puts("failed to parse
|
94
|
+
puts("failed to parse old response: #{$!.message}")
|
93
95
|
puts(response1)
|
94
96
|
valid = false
|
95
97
|
end
|
96
98
|
|
97
99
|
begin
|
98
|
-
JSON.parse(
|
100
|
+
JSON.parse(response_new)
|
99
101
|
rescue JSON::ParserError
|
100
102
|
puts(command)
|
101
|
-
puts("failed to parse
|
103
|
+
puts("failed to parse new response: #{$!.message}")
|
102
104
|
puts(response2)
|
103
105
|
valid = false
|
104
106
|
end
|
@@ -106,23 +108,37 @@ module Groonga
|
|
106
108
|
valid
|
107
109
|
end
|
108
110
|
|
109
|
-
def report_diff(command,
|
110
|
-
return if
|
111
|
+
def report_diff(command, response_old, response_new)
|
112
|
+
return if response_old == response_new
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
puts(command)
|
114
|
+
Tempfile.open("response-old") do |response_old_file|
|
115
|
+
PP.pp(JSON.parse(response_old), response_old_file)
|
116
|
+
response_old_file.flush
|
117
|
+
Tempfile.open("response-new") do |response_new_file|
|
118
|
+
PP.pp(JSON.parse(response_new), response_new_file)
|
119
|
+
response_new_file.flush
|
120
|
+
report_command(command)
|
120
121
|
system("diff",
|
122
|
+
"--label=old",
|
123
|
+
"--label=new",
|
121
124
|
"-u",
|
122
|
-
|
125
|
+
response_old_file.path, response_new_file.path)
|
123
126
|
end
|
124
127
|
end
|
125
128
|
end
|
129
|
+
|
130
|
+
def report_command(command)
|
131
|
+
puts(command)
|
132
|
+
parsed_command = Groonga::Command::Parser.parse(command)
|
133
|
+
puts("Name: #{parsed_command.name}")
|
134
|
+
puts("Arguments:")
|
135
|
+
sorted_arguments = parsed_command.arguments.sort_by do |key, value|
|
136
|
+
key
|
137
|
+
end
|
138
|
+
sorted_arguments.each do |key, value|
|
139
|
+
puts(" #{key}: #{value}")
|
140
|
+
end
|
141
|
+
end
|
126
142
|
end
|
127
143
|
end
|
128
144
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/query-log/command/format-regression-test-logs"
|
20
|
+
|
21
|
+
class FormatRegressionTestLogsCommandTest < Test::Unit::TestCase
|
22
|
+
include Path
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@command = Groonga::QueryLog::Command::FormatRegressionTestLogs.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_command(command_line)
|
29
|
+
stdout = $stdout.dup
|
30
|
+
output = Tempfile.open("output")
|
31
|
+
$stdout.reopen(output)
|
32
|
+
succees = @command.run(command_line)
|
33
|
+
output.rewind
|
34
|
+
[succees, output.read]
|
35
|
+
ensure
|
36
|
+
$stdout.reopen(stdout)
|
37
|
+
end
|
38
|
+
|
39
|
+
def fixture_path(*components)
|
40
|
+
super("regression-test-logs", *components)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_nothing
|
44
|
+
input = Tempfile.new("format-regression-test-logs")
|
45
|
+
assert_equal([true, ""],
|
46
|
+
run_command([input.path]))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_command_format
|
50
|
+
output = <<-OUTPUT
|
51
|
+
select Logs
|
52
|
+
Name: select
|
53
|
+
Arguments:
|
54
|
+
table: Logs
|
55
|
+
--- old
|
56
|
+
+++ new
|
57
|
+
@@ -1,4 +1,4 @@
|
58
|
+
[[[2],
|
59
|
+
[[\"_id\", \"UInt32\"], [\"message\", \"Text\"]],
|
60
|
+
[1, \"log message1\"],
|
61
|
+
- [2, \"log message2\"]]]
|
62
|
+
+ [3, \"log message3\"]]]
|
63
|
+
OUTPUT
|
64
|
+
assert_equal([true, output],
|
65
|
+
run_command([fixture_path("command-format.log")]))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_url_format
|
69
|
+
output = <<-OUTPUT
|
70
|
+
/d/select?table=Logs&match_columns=message&query=%E7%84%BC%E8%82%89
|
71
|
+
Name: select
|
72
|
+
Arguments:
|
73
|
+
match_columns: message
|
74
|
+
query: 焼肉
|
75
|
+
table: Logs
|
76
|
+
--- old
|
77
|
+
+++ new
|
78
|
+
@@ -1,4 +1,4 @@
|
79
|
+
[[[2],
|
80
|
+
[[\"_id\", \"UInt32\"], [\"message\", \"Text\"]],
|
81
|
+
[1, \"log message1: 焼肉\"],
|
82
|
+
- [2, \"log message2: 焼肉\"]]]
|
83
|
+
+ [3, \"log message3: 焼肉\"]]]
|
84
|
+
OUTPUT
|
85
|
+
assert_equal([true, output],
|
86
|
+
run_command([fixture_path("url-format.log")]))
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,3 @@
|
|
1
|
+
command: /d/select?table=Logs&match_columns=message&query=%E7%84%BC%E8%82%89
|
2
|
+
response1: [[[2], [["_id", "UInt32"], ["message", "Text"]], [1, "log message1: 焼肉"], [2, "log message2: 焼肉"]]]
|
3
|
+
response2: [[[2], [["_id", "UInt32"], ["message", "Text"]], [1, "log message1: 焼肉"], [3, "log message3: 焼肉"]]]
|
data/test/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "cgi"
|
20
|
+
require "stringio"
|
21
|
+
|
22
|
+
require "groonga/command"
|
23
|
+
|
24
|
+
require "groonga/query-log"
|
25
|
+
|
26
|
+
module Path
|
27
|
+
def fixture_path(*components)
|
28
|
+
File.join(File.dirname(__FILE__), "fixtures", *components)
|
29
|
+
end
|
30
|
+
end
|
data/test/run-test.rb
CHANGED
@@ -47,7 +47,7 @@ Test::Unit::Priority.enable
|
|
47
47
|
$LOAD_PATH.unshift(lib_dir.to_s)
|
48
48
|
|
49
49
|
$LOAD_PATH.unshift(test_dir.to_s)
|
50
|
-
require "
|
50
|
+
require "helper"
|
51
51
|
|
52
52
|
Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
|
53
53
|
require file.sub(/\.rb\z/, '')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-query-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: groonga-command-parser
|
@@ -211,7 +211,7 @@ files:
|
|
211
211
|
- lib/groonga/query-log/response-comparer.rb
|
212
212
|
- lib/groonga/query-log/server-verifier.rb
|
213
213
|
- lib/groonga/query-log/version.rb
|
214
|
-
- test/command/test-
|
214
|
+
- test/command/test-format-regression-test-logs.rb
|
215
215
|
- test/fixtures/multi.expected
|
216
216
|
- test/fixtures/n_entries.expected
|
217
217
|
- test/fixtures/no-report-summary.expected
|
@@ -221,11 +221,13 @@ files:
|
|
221
221
|
- test/fixtures/order/start-time.expected
|
222
222
|
- test/fixtures/other-query.log
|
223
223
|
- test/fixtures/query.log
|
224
|
+
- test/fixtures/regression-test-logs/command-format.log
|
225
|
+
- test/fixtures/regression-test-logs/url-format.log
|
224
226
|
- test/fixtures/reporter/console.expected
|
225
227
|
- test/fixtures/reporter/html.expected
|
226
228
|
- test/fixtures/reporter/json-stream.expected
|
227
229
|
- test/fixtures/reporter/json.expected
|
228
|
-
- test/
|
230
|
+
- test/helper.rb
|
229
231
|
- test/run-test.rb
|
230
232
|
- test/test-analyzer.rb
|
231
233
|
- test/test-extractor.rb
|
@@ -263,9 +265,8 @@ summary: Groonga-query-log is a collection of library and tools to process [Groo
|
|
263
265
|
test_files:
|
264
266
|
- test/test-analyzer.rb
|
265
267
|
- test/test-parser.rb
|
266
|
-
- test/groonga-query-log-test-utils.rb
|
267
268
|
- test/test-response-comparer.rb
|
268
|
-
- test/command/test-
|
269
|
+
- test/command/test-format-regression-test-logs.rb
|
269
270
|
- test/fixtures/other-query.log
|
270
271
|
- test/fixtures/reporter/console.expected
|
271
272
|
- test/fixtures/reporter/html.expected
|
@@ -274,11 +275,14 @@ test_files:
|
|
274
275
|
- test/fixtures/query.log
|
275
276
|
- test/fixtures/multi.expected
|
276
277
|
- test/fixtures/no-report-summary.expected
|
278
|
+
- test/fixtures/regression-test-logs/url-format.log
|
279
|
+
- test/fixtures/regression-test-logs/command-format.log
|
277
280
|
- test/fixtures/n_entries.expected
|
278
281
|
- test/fixtures/order/-start-time.expected
|
279
282
|
- test/fixtures/order/elapsed.expected
|
280
283
|
- test/fixtures/order/start-time.expected
|
281
284
|
- test/fixtures/order/-elapsed.expected
|
285
|
+
- test/helper.rb
|
282
286
|
- test/run-test.rb
|
283
287
|
- test/test-incompatibility-detector.rb
|
284
288
|
- test/test-extractor.rb
|
data/test/command/test-select.rb
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License as published by the Free Software Foundation; either
|
8
|
-
# version 2.1 of the License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This library is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# Lesser General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU Lesser General Public
|
16
|
-
# License along with this library; if not, write to the Free Software
|
17
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
-
|
19
|
-
class SelectCommandTest < Test::Unit::TestCase
|
20
|
-
module ParseTests
|
21
|
-
def test_parameters
|
22
|
-
select = parse("select",
|
23
|
-
:table => "Users",
|
24
|
-
:filter => "age<=30")
|
25
|
-
assert_equal(command("select",
|
26
|
-
"table" => "Users",
|
27
|
-
"filter" => "age<=30",
|
28
|
-
"output_type" => "json"),
|
29
|
-
select)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_scorer
|
33
|
-
select = parse("select",
|
34
|
-
:table => "Users",
|
35
|
-
:filter => "age<=30",
|
36
|
-
:scorer => "_score = random()")
|
37
|
-
assert_equal("_score = random()", select.scorer)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_to_uri_format
|
41
|
-
select = parse("select",
|
42
|
-
:table => "Users",
|
43
|
-
:filter => "age<=30")
|
44
|
-
assert_equal("/d/select.json?filter=age%3C%3D30&table=Users",
|
45
|
-
select.to_uri_format)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_to_command_format
|
49
|
-
select = parse("select",
|
50
|
-
:table => "Users",
|
51
|
-
:filter => "age<=30")
|
52
|
-
assert_equal("select --filter \"age<=30\" " +
|
53
|
-
"--output_type \"json\" --table \"Users\"",
|
54
|
-
select.to_command_format)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module ParseFilterTests
|
59
|
-
def test_parenthesis
|
60
|
-
filter = 'geo_in_rectangle(location,' +
|
61
|
-
'"35.73360x139.7394","62614x139.7714") && ' +
|
62
|
-
'((type == "たいやき" || type == "和菓子")) && ' +
|
63
|
-
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
64
|
-
select = parse("select",
|
65
|
-
:table => "Users",
|
66
|
-
:filter => filter)
|
67
|
-
assert_equal(['geo_in_rectangle(location,' +
|
68
|
-
'"35.73360x139.7394","62614x139.7714")',
|
69
|
-
'type == "たいやき"',
|
70
|
-
'type == "和菓子"',
|
71
|
-
'keyword @ "たいやき"',
|
72
|
-
'keyword @ "白"',
|
73
|
-
'keyword @ "養殖"'],
|
74
|
-
select.conditions)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_to_uri_format
|
78
|
-
filter = 'geo_in_rectangle(location,' +
|
79
|
-
'"35.73360x139.7394","62614x139.7714") && ' +
|
80
|
-
'((type == "たいやき" || type == "和菓子")) && ' +
|
81
|
-
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
82
|
-
select = parse("select",
|
83
|
-
:table => "Users",
|
84
|
-
:filter => filter)
|
85
|
-
assert_equal("/d/select.json?filter=geo_in_rectangle%28location%2C" +
|
86
|
-
"%2235.73360x139.7394%22%2C%2262614x139.7714%22%29+" +
|
87
|
-
"%26%26+%28%28type+" +
|
88
|
-
"%3D%3D+%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+" +
|
89
|
-
"%7C%7C+type+%3D%3D+" +
|
90
|
-
"%22%E5%92%8C%E8%8F%93%E5%AD%90%22%29%29+" +
|
91
|
-
"%26%26+keyword+%40+" +
|
92
|
-
"%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+%26%21+" +
|
93
|
-
"keyword+%40+%22%E7%99%BD%22+%26%21+" +
|
94
|
-
"keyword+%40+%22%E9%A4%8A%E6%AE%96%22&table=Users",
|
95
|
-
select.to_uri_format)
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_to_command_format
|
99
|
-
filter = 'geo_in_rectangle(location,' +
|
100
|
-
'"35.73360x139.7394","62614x139.7714") && ' +
|
101
|
-
'((type == "たいやき" || type == "和菓子")) && ' +
|
102
|
-
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
103
|
-
select = parse("select",
|
104
|
-
:table => "Users",
|
105
|
-
:filter => filter)
|
106
|
-
assert_equal("select " +
|
107
|
-
"--filter " +
|
108
|
-
"\"geo_in_rectangle(location," +
|
109
|
-
"\\\"35.73360x139.7394\\\",\\\"62614x139.7714\\\") && " +
|
110
|
-
"((type == \\\"たいやき\\\" || " +
|
111
|
-
"type == \\\"和菓子\\\")) && " +
|
112
|
-
"keyword @ \\\"たいやき\\\" &! keyword @ \\\"白\\\" &! " +
|
113
|
-
"keyword @ \\\"養殖\\\"\" " +
|
114
|
-
"--output_type \"json\" --table \"Users\"",
|
115
|
-
select.to_command_format)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class HTTPTest < self
|
120
|
-
include GroongaQueryLogTestUtils::HTTPCommandParser
|
121
|
-
|
122
|
-
def test_uri_format?
|
123
|
-
command = parse("status")
|
124
|
-
assert_predicate(command, :uri_format?)
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_command_format?
|
128
|
-
command = parse("status")
|
129
|
-
assert_not_predicate(command, :command_format?)
|
130
|
-
end
|
131
|
-
|
132
|
-
class ParseTest < self
|
133
|
-
include ParseTests
|
134
|
-
end
|
135
|
-
|
136
|
-
class ParseFilterTest < self
|
137
|
-
include ParseFilterTests
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
class CommandLineTest < self
|
142
|
-
include GroongaQueryLogTestUtils::CommandLineCommandParser
|
143
|
-
|
144
|
-
def test_uri_format?
|
145
|
-
command = parse("status")
|
146
|
-
assert_not_predicate(command, :uri_format?)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_command_format?
|
150
|
-
command = parse("status")
|
151
|
-
assert_predicate(command, :command_format?)
|
152
|
-
end
|
153
|
-
|
154
|
-
class ParseTest < self
|
155
|
-
include ParseTests
|
156
|
-
end
|
157
|
-
|
158
|
-
class ParseFilterTest < self
|
159
|
-
include ParseFilterTests
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License as published by the Free Software Foundation; either
|
8
|
-
# version 2.1 of the License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This library is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# Lesser General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU Lesser General Public
|
16
|
-
# License along with this library; if not, write to the Free Software
|
17
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
-
|
19
|
-
require "cgi"
|
20
|
-
require "stringio"
|
21
|
-
|
22
|
-
require "groonga/command"
|
23
|
-
|
24
|
-
require "groonga/query-log"
|
25
|
-
|
26
|
-
module GroongaQueryLogTestUtils
|
27
|
-
module CommandParser
|
28
|
-
private
|
29
|
-
def command(name, parameters)
|
30
|
-
command_class = Groonga::Command.find(name)
|
31
|
-
command = command_class.new(name, parameters)
|
32
|
-
command.original_format = :command
|
33
|
-
command
|
34
|
-
end
|
35
|
-
|
36
|
-
def parse_http_path(command, parameters)
|
37
|
-
path = "/d/#{command}.json"
|
38
|
-
unless parameters.empty?
|
39
|
-
uri_parameters = parameters.collect do |key, value|
|
40
|
-
[CGI.escape(key.to_s), CGI.escape(value.to_s)].join("=")
|
41
|
-
end
|
42
|
-
path << "?"
|
43
|
-
path << uri_parameters.join("&")
|
44
|
-
end
|
45
|
-
Groonga::Command::Parser.parse(path)
|
46
|
-
end
|
47
|
-
|
48
|
-
def parse_command_line(command, parameters)
|
49
|
-
command_line = "#{command} --output_type json"
|
50
|
-
parameters.each do |key, value|
|
51
|
-
if /"| / =~ value
|
52
|
-
escaped_value = '"' + value.gsub(/"/, '\"') + '"'
|
53
|
-
else
|
54
|
-
escaped_value = value
|
55
|
-
end
|
56
|
-
command_line << " --#{key} #{escaped_value}"
|
57
|
-
end
|
58
|
-
Groonga::Command::Parser.parse(command_line)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
module HTTPCommandParser
|
63
|
-
include CommandParser
|
64
|
-
|
65
|
-
private
|
66
|
-
def parse(command, parameters={})
|
67
|
-
parse_http_path(command, parameters)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module CommandLineCommandParser
|
72
|
-
include CommandParser
|
73
|
-
|
74
|
-
private
|
75
|
-
def parse(command, parameters={})
|
76
|
-
parse_command_line(command, parameters)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|