groonga-client 0.3.3 → 0.3.4
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 +13 -0
- data/lib/groonga/client.rb +1 -1
- data/lib/groonga/client/request.rb +22 -0
- data/lib/groonga/client/request/base.rb +174 -0
- data/lib/groonga/client/request/error.rb +39 -0
- data/lib/groonga/client/request/select.rb +292 -0
- data/lib/groonga/client/response/schema.rb +25 -9
- data/lib/groonga/client/response/select.rb +64 -2
- data/lib/groonga/client/spec-helper.rb +37 -0
- data/lib/groonga/client/test-helper.rb +37 -0
- data/lib/groonga/client/test/fixture.rb +35 -0
- data/lib/groonga/client/test/groonga-server-runner.rb +158 -0
- data/lib/groonga/client/version.rb +1 -1
- data/test/request/select/test-filter-parameter.rb +97 -0
- data/test/request/select/test-output-columns-parameter.rb +75 -0
- data/test/request/select/test-sort-keys-columns-parameter.rb +74 -0
- data/test/request/select/test-values-parameter.rb +58 -0
- data/test/request/test-base.rb +50 -0
- data/test/request/test-select.rb +131 -0
- data/test/response/test-schema.rb +342 -0
- data/test/response/test-select-command-version1.rb +68 -0
- data/test/response/test-select-command-version3.rb +70 -0
- data/test/run-test.rb +1 -0
- metadata +36 -16
@@ -0,0 +1,97 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestSelectFilterParmater < Test::Unit::TestCase
|
18
|
+
def filter_parameter(expression, values=nil)
|
19
|
+
Groonga::Client::Request::Select::FilterParameter.new(expression, values)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_parameters(expression, values=nil)
|
23
|
+
filter_parameter(expression, values).to_parameters
|
24
|
+
end
|
25
|
+
|
26
|
+
sub_test_case("expression") do
|
27
|
+
def test_nil
|
28
|
+
assert_equal({},
|
29
|
+
to_parameters(nil))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_string
|
33
|
+
assert_equal({
|
34
|
+
:filter => "age <= 20",
|
35
|
+
},
|
36
|
+
to_parameters("age <= 20"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_empty_string
|
40
|
+
assert_equal({},
|
41
|
+
to_parameters(""))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
sub_test_case("values") do
|
46
|
+
def test_string
|
47
|
+
filter = <<-'FILTER'.strip
|
48
|
+
title == "[\"He\\ llo\"]"
|
49
|
+
FILTER
|
50
|
+
assert_equal({
|
51
|
+
:filter => filter,
|
52
|
+
},
|
53
|
+
to_parameters("title == %{value}",
|
54
|
+
:value => "[\"He\\ llo\"]"))
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_symbol
|
58
|
+
assert_equal({
|
59
|
+
:filter => "title == \"Hello\"",
|
60
|
+
},
|
61
|
+
to_parameters("title == %{value}",
|
62
|
+
:value => :Hello))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_number
|
66
|
+
assert_equal({
|
67
|
+
:filter => "age <= 29",
|
68
|
+
},
|
69
|
+
to_parameters("age <= %{value}",
|
70
|
+
:value => 29))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_true
|
74
|
+
assert_equal({
|
75
|
+
:filter => "published == true",
|
76
|
+
},
|
77
|
+
to_parameters("published == %{value}",
|
78
|
+
:value => true))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_false
|
82
|
+
assert_equal({
|
83
|
+
:filter => "published == false",
|
84
|
+
},
|
85
|
+
to_parameters("published == %{value}",
|
86
|
+
:value => false))
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_nil
|
90
|
+
assert_equal({
|
91
|
+
:filter => "function(null)",
|
92
|
+
},
|
93
|
+
to_parameters("function(%{value})",
|
94
|
+
:value => nil))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestSelectOutputColumnsParmater < Test::Unit::TestCase
|
18
|
+
def output_columns_parameter(prefix, output_columns)
|
19
|
+
Groonga::Client::Request::Select::OutputColumnsParameter.new(prefix,
|
20
|
+
output_columns)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_nil
|
24
|
+
assert_equal({},
|
25
|
+
output_columns_parameter("", nil).to_parameters)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_string
|
29
|
+
assert_equal({
|
30
|
+
:output_columns => "title",
|
31
|
+
},
|
32
|
+
output_columns_parameter("", "title").to_parameters)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_empty_string
|
36
|
+
assert_equal({},
|
37
|
+
output_columns_parameter("", "").to_parameters)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_symbol
|
41
|
+
assert_equal({
|
42
|
+
:output_columns => "title",
|
43
|
+
},
|
44
|
+
output_columns_parameter("", :title).to_parameters)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_array
|
48
|
+
assert_equal({
|
49
|
+
:output_columns => "title, body",
|
50
|
+
},
|
51
|
+
output_columns_parameter("", ["title", "body"]).to_parameters)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_empty_array
|
55
|
+
assert_equal({},
|
56
|
+
output_columns_parameter("", []).to_parameters)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_function
|
60
|
+
parameter = output_columns_parameter("", ["title", "snippet_html(body)"])
|
61
|
+
assert_equal({
|
62
|
+
:output_columns => "title, snippet_html(body)",
|
63
|
+
:command_version => "2",
|
64
|
+
},
|
65
|
+
parameter.to_parameters)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_prefix
|
69
|
+
parameter = output_columns_parameter("drilldowns[title].", "title")
|
70
|
+
assert_equal({
|
71
|
+
:"drilldowns[title].output_columns" => "title",
|
72
|
+
},
|
73
|
+
parameter.to_parameters)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestSelectSortKeysParmater < Test::Unit::TestCase
|
18
|
+
def sort_keys_parameter(prefix, sort_keys)
|
19
|
+
Groonga::Client::Request::Select::SortKeysParameter.new(prefix, sort_keys)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_parameters(sort_keys)
|
23
|
+
sort_keys_parameter("", sort_keys).to_parameters
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_nil
|
27
|
+
assert_equal({},
|
28
|
+
to_parameters(nil))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_string
|
32
|
+
assert_equal({
|
33
|
+
:sort_keys => "-_score, _id",
|
34
|
+
:sortby => "-_score, _id",
|
35
|
+
},
|
36
|
+
to_parameters("-_score, _id"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_empty_string
|
40
|
+
assert_equal({},
|
41
|
+
to_parameters(""))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_symbol
|
45
|
+
assert_equal({
|
46
|
+
:sort_keys => "_score",
|
47
|
+
:sortby => "_score",
|
48
|
+
},
|
49
|
+
to_parameters(:_score))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_array
|
53
|
+
assert_equal({
|
54
|
+
:sort_keys => "-_score, _id",
|
55
|
+
:sortby => "-_score, _id",
|
56
|
+
},
|
57
|
+
to_parameters(["-_score", :_id]))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_empty_array
|
61
|
+
assert_equal({},
|
62
|
+
to_parameters([]))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_prefix
|
66
|
+
parameter = sort_keys_parameter("slices[tag].", "-_score, _id")
|
67
|
+
|
68
|
+
assert_equal({
|
69
|
+
:"slices[tag].sort_keys" => "-_score, _id",
|
70
|
+
:"slices[tag].sortby" => "-_score, _id",
|
71
|
+
},
|
72
|
+
parameter.to_parameters)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestSelectValuesParmater < Test::Unit::TestCase
|
18
|
+
def values_parameter(values)
|
19
|
+
names = [:match_columns]
|
20
|
+
Groonga::Client::Request::ValuesParameter.new(names, values)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_nil
|
24
|
+
assert_equal({},
|
25
|
+
values_parameter(nil).to_parameters)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_string
|
29
|
+
assert_equal({
|
30
|
+
:match_columns => "title",
|
31
|
+
},
|
32
|
+
values_parameter("title").to_parameters)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_empty_string
|
36
|
+
assert_equal({},
|
37
|
+
values_parameter("").to_parameters)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_symbol
|
41
|
+
assert_equal({
|
42
|
+
:match_columns => "title",
|
43
|
+
},
|
44
|
+
values_parameter(:title).to_parameters)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_array
|
48
|
+
assert_equal({
|
49
|
+
:match_columns => "title, body",
|
50
|
+
},
|
51
|
+
values_parameter(["title", "body"]).to_parameters)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_empty_array
|
55
|
+
assert_equal({},
|
56
|
+
values_parameter([]).to_parameters)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestBase < Test::Unit::TestCase
|
18
|
+
sub_test_case "#extensions" do
|
19
|
+
setup do
|
20
|
+
@request = Groonga::Client::Request::Base.new("status")
|
21
|
+
end
|
22
|
+
|
23
|
+
test "Module" do
|
24
|
+
assert do
|
25
|
+
not @request.respond_to?(:new_method)
|
26
|
+
end
|
27
|
+
extension = Module.new do
|
28
|
+
def new_method
|
29
|
+
end
|
30
|
+
end
|
31
|
+
extended_request = @request.extensions(extension)
|
32
|
+
assert do
|
33
|
+
extended_request.respond_to?(:new_method)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
test "block" do
|
38
|
+
assert do
|
39
|
+
not @request.respond_to?(:new_method)
|
40
|
+
end
|
41
|
+
extended_request = @request.extensions do
|
42
|
+
def new_method
|
43
|
+
end
|
44
|
+
end
|
45
|
+
assert do
|
46
|
+
extended_request.respond_to?(:new_method)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestSelect < Test::Unit::TestCase
|
18
|
+
setup do
|
19
|
+
@request = Groonga::Client::Request::Select.new("posts")
|
20
|
+
end
|
21
|
+
|
22
|
+
sub_test_case("#drilldowns") do
|
23
|
+
def drilldown
|
24
|
+
@request.drilldowns("label")
|
25
|
+
end
|
26
|
+
|
27
|
+
sub_test_case("#keys") do
|
28
|
+
test "String" do
|
29
|
+
assert_equal({
|
30
|
+
:table => "posts",
|
31
|
+
:"drilldowns[label].keys" => "tag",
|
32
|
+
},
|
33
|
+
drilldown.keys("tag").to_parameters)
|
34
|
+
end
|
35
|
+
|
36
|
+
test "Array" do
|
37
|
+
assert_equal({
|
38
|
+
:table => "posts",
|
39
|
+
:"drilldowns[label].keys" => "start, end",
|
40
|
+
},
|
41
|
+
drilldown.keys(["start", "end"]).to_parameters)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
sub_test_case("#sort_keys") do
|
46
|
+
test "String" do
|
47
|
+
assert_equal({
|
48
|
+
:table => "posts",
|
49
|
+
:"drilldowns[label].sort_keys" => "-_nsubrecs",
|
50
|
+
:"drilldowns[label].sortby" => "-_nsubrecs",
|
51
|
+
},
|
52
|
+
drilldown.sort_keys("-_nsubrecs").to_parameters)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "Array" do
|
56
|
+
assert_equal({
|
57
|
+
:table => "posts",
|
58
|
+
:"drilldowns[label].sort_keys" => "-_nsubrecs, name",
|
59
|
+
:"drilldowns[label].sortby" => "-_nsubrecs, name",
|
60
|
+
},
|
61
|
+
drilldown.sort_keys(["-_nsubrecs", "name"]).to_parameters)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
sub_test_case("#output_columns") do
|
66
|
+
test "String" do
|
67
|
+
assert_equal({
|
68
|
+
:table => "posts",
|
69
|
+
:"drilldowns[label].output_columns" => "_key, -_nsubrecs",
|
70
|
+
},
|
71
|
+
drilldown.output_columns("_key, -_nsubrecs").to_parameters)
|
72
|
+
end
|
73
|
+
|
74
|
+
test "Array" do
|
75
|
+
assert_equal({
|
76
|
+
:table => "posts",
|
77
|
+
:"drilldowns[label].output_columns" => "_key, -_nsubrecs",
|
78
|
+
},
|
79
|
+
drilldown.output_columns(["_key, -_nsubrecs"]).to_parameters)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
sub_test_case("#offset") do
|
84
|
+
test "Integer" do
|
85
|
+
assert_equal({
|
86
|
+
:table => "posts",
|
87
|
+
:"drilldowns[label].offset" => 29,
|
88
|
+
},
|
89
|
+
drilldown.offset(29).to_parameters)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
sub_test_case("#limit") do
|
94
|
+
test "Integer" do
|
95
|
+
assert_equal({
|
96
|
+
:table => "posts",
|
97
|
+
:"drilldowns[label].limit" => 29,
|
98
|
+
},
|
99
|
+
drilldown.limit(29).to_parameters)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
sub_test_case("#calc_types") do
|
104
|
+
test "String" do
|
105
|
+
assert_equal({
|
106
|
+
:table => "posts",
|
107
|
+
:"drilldowns[label].calc_types" => "COUNT|AVG",
|
108
|
+
},
|
109
|
+
drilldown.calc_types("COUNT|AVG").to_parameters)
|
110
|
+
end
|
111
|
+
|
112
|
+
test "Array" do
|
113
|
+
assert_equal({
|
114
|
+
:table => "posts",
|
115
|
+
:"drilldowns[label].calc_types" => "COUNT|AVG",
|
116
|
+
},
|
117
|
+
drilldown.calc_types(["COUNT", "AVG"]).to_parameters)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
sub_test_case("#calc_target") do
|
122
|
+
test "Symbol" do
|
123
|
+
assert_equal({
|
124
|
+
:table => "posts",
|
125
|
+
:"drilldowns[label].calc_target" => "rank",
|
126
|
+
},
|
127
|
+
drilldown.calc_target(:rank).to_parameters)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|