groonga-client 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,292 @@
1
+ # Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
2
+ # Copyright (C) 2017 Kentaro Hayashi <hayashi@clear-code.com>
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ require_relative "helper"
19
+
20
+ require "groonga/client/command-line/groonga-client-index-check"
21
+
22
+ class TestCommandLineIndexCheck < Test::Unit::TestCase
23
+ include Groonga::Client::TestHelper
24
+ include CommandLineTestHelper
25
+
26
+ def index_check(*arguments)
27
+ command_line = Groonga::Client::CommandLine::GroongaClientIndexCheck.new
28
+ capture_outputs do
29
+ command_line.run(["--url", groonga_url, *arguments])
30
+ end
31
+ end
32
+
33
+ def test_source
34
+ restore(<<-COMMANDS)
35
+ table_create Memos TABLE_HASH_KEY ShortText
36
+ column_create Memos content COLUMN_SCALAR Text
37
+
38
+ table_create Terms TABLE_PAT_KEY ShortText \
39
+ --normalizer NormalizerAuto \
40
+ --default_tokenizer TokenBigram
41
+ column_create Terms memos_content \
42
+ COLUMN_INDEX|WITH_POSITION \
43
+ Memos
44
+ COMMANDS
45
+
46
+ error_output = <<-OUTPUT
47
+ Source is missing: <Terms.memos_content>
48
+ OUTPUT
49
+
50
+ assert_equal([false, "", error_output],
51
+ index_check("--method=source"))
52
+ end
53
+
54
+ sub_test_case("content") do
55
+ def test_valid
56
+ restore(<<-COMMANDS)
57
+ table_create Memos TABLE_HASH_KEY ShortText
58
+ column_create Memos content COLUMN_SCALAR Text
59
+
60
+ table_create Terms TABLE_PAT_KEY ShortText \
61
+ --normalizer NormalizerAuto \
62
+ --default_tokenizer TokenBigram
63
+ column_create Terms memos_content \
64
+ COLUMN_INDEX|WITH_POSITION \
65
+ Memos content
66
+
67
+ load --table Memos
68
+ [
69
+ ["_key", "content"],
70
+ ["groonga", "Groonga is fast"]
71
+ ]
72
+ COMMANDS
73
+
74
+ assert_equal([true, "", ""],
75
+ index_check("--method=content"))
76
+ end
77
+
78
+ def test_all
79
+ restore(<<-COMMANDS)
80
+ table_create Memos TABLE_HASH_KEY ShortText
81
+ column_create Memos content COLUMN_SCALAR Text
82
+
83
+ table_create Terms TABLE_PAT_KEY ShortText \
84
+ --normalizer NormalizerAuto \
85
+ --default_tokenizer TokenBigram
86
+ column_create Terms memos_content1 \
87
+ COLUMN_INDEX|WITH_POSITION \
88
+ Memos content
89
+ column_create Terms memos_content2 \
90
+ COLUMN_INDEX|WITH_POSITION \
91
+ Memos content
92
+
93
+ load --table Memos
94
+ [
95
+ ["_key", "content"],
96
+ ["groonga", "Groonga is fast"]
97
+ ]
98
+
99
+ delete --table Terms --key is
100
+ COMMANDS
101
+
102
+ assert_equal([
103
+ false,
104
+ "",
105
+ "Broken: Terms.memos_content1: <is>\n" +
106
+ "Broken: Terms.memos_content2: <is>\n",
107
+ ],
108
+ index_check("--method=content"))
109
+ end
110
+
111
+ def test_table
112
+ restore(<<-COMMANDS)
113
+ table_create Memos TABLE_HASH_KEY ShortText
114
+ column_create Memos content COLUMN_SCALAR Text
115
+
116
+ table_create Terms1 TABLE_PAT_KEY ShortText \
117
+ --normalizer NormalizerAuto \
118
+ --default_tokenizer TokenBigram
119
+ column_create Terms1 memos_content1 \
120
+ COLUMN_INDEX|WITH_POSITION \
121
+ Memos content
122
+ column_create Terms1 memos_content2 \
123
+ COLUMN_INDEX|WITH_POSITION \
124
+ Memos content
125
+
126
+ table_create Terms2 TABLE_PAT_KEY ShortText \
127
+ --normalizer NormalizerAuto \
128
+ --default_tokenizer TokenBigram
129
+ column_create Terms2 memos_content \
130
+ COLUMN_INDEX|WITH_POSITION \
131
+ Memos content
132
+
133
+ load --table Memos
134
+ [
135
+ ["_key", "content"],
136
+ ["groonga", "Groonga is fast"]
137
+ ]
138
+
139
+ delete --table Terms1 --key is
140
+ delete --table Terms2 --key is
141
+ COMMANDS
142
+
143
+ assert_equal([
144
+ false,
145
+ "",
146
+ "Broken: Terms1.memos_content1: <is>\n" +
147
+ "Broken: Terms1.memos_content2: <is>\n",
148
+ ],
149
+ index_check("--method=content", "Terms1"))
150
+ end
151
+
152
+ def test_index_column
153
+ restore(<<-COMMANDS)
154
+ table_create Memos TABLE_HASH_KEY ShortText
155
+ column_create Memos content COLUMN_SCALAR Text
156
+
157
+ table_create Terms TABLE_PAT_KEY ShortText \
158
+ --normalizer NormalizerAuto \
159
+ --default_tokenizer TokenBigram
160
+ column_create Terms memos_content1 \
161
+ COLUMN_INDEX|WITH_POSITION \
162
+ Memos content
163
+ column_create Terms memos_content2 \
164
+ COLUMN_INDEX|WITH_POSITION \
165
+ Memos content
166
+
167
+ load --table Memos
168
+ [
169
+ ["_key", "content"],
170
+ ["groonga", "Groonga is fast"]
171
+ ]
172
+
173
+ delete --table Terms --key is
174
+ COMMANDS
175
+
176
+ assert_equal([
177
+ false,
178
+ "",
179
+ "Broken: Terms.memos_content1: <is>\n",
180
+ ],
181
+ index_check("--method=content", "Terms.memos_content1"))
182
+ end
183
+
184
+ def test_index_columns
185
+ restore(<<-COMMANDS)
186
+ table_create Memos TABLE_HASH_KEY ShortText
187
+ column_create Memos content COLUMN_SCALAR Text
188
+
189
+ table_create Terms TABLE_PAT_KEY ShortText \
190
+ --normalizer NormalizerAuto \
191
+ --default_tokenizer TokenBigram
192
+ column_create Terms memos_content1 \
193
+ COLUMN_INDEX|WITH_POSITION \
194
+ Memos content
195
+ column_create Terms memos_content2 \
196
+ COLUMN_INDEX|WITH_POSITION \
197
+ Memos content
198
+ column_create Terms memos_content3 \
199
+ COLUMN_INDEX|WITH_POSITION \
200
+ Memos content
201
+
202
+ load --table Memos
203
+ [
204
+ ["_key", "content"],
205
+ ["groonga", "Groonga is fast"]
206
+ ]
207
+
208
+ delete --table Terms --key is
209
+ COMMANDS
210
+
211
+ assert_equal([
212
+ false,
213
+ "",
214
+ "Broken: Terms.memos_content1: <is>\n" +
215
+ "Broken: Terms.memos_content2: <is>\n",
216
+ ],
217
+ index_check("--method=content",
218
+ "Terms.memos_content1",
219
+ "Terms.memos_content2"))
220
+ end
221
+
222
+ def test_key
223
+ restore(<<-COMMANDS)
224
+ table_create Memos TABLE_HASH_KEY ShortText
225
+
226
+ table_create Terms TABLE_PAT_KEY ShortText \
227
+ --normalizer NormalizerAuto \
228
+ --default_tokenizer TokenBigram
229
+ column_create Terms memos_key \
230
+ COLUMN_INDEX|WITH_POSITION \
231
+ Memos _key
232
+
233
+ load --table Memos
234
+ [
235
+ {"_key": "groonga"}
236
+ ]
237
+
238
+ delete Terms --key groonga
239
+ COMMANDS
240
+
241
+ assert_equal([false, "", "Broken: Terms.memos_key: <groonga>\n"],
242
+ index_check("--method=content"))
243
+ end
244
+
245
+ def test_multiple_column
246
+ restore(<<-COMMANDS)
247
+ table_create Memos TABLE_HASH_KEY ShortText
248
+ column_create Memos content COLUMN_SCALAR Text
249
+
250
+ table_create Terms TABLE_PAT_KEY ShortText \
251
+ --normalizer NormalizerAuto \
252
+ --default_tokenizer TokenBigram
253
+ column_create Terms memos \
254
+ COLUMN_INDEX|WITH_SECTION|WITH_POSITION \
255
+ Memos _key,content
256
+
257
+ load --table Memos
258
+ [
259
+ {"_key": "groonga", "content": "Groonga is fast"}
260
+ ]
261
+
262
+ delete Terms --key is
263
+ COMMANDS
264
+
265
+ assert_equal([false, "", "Broken: Terms.memos: <is>\n"],
266
+ index_check("--method=content"))
267
+ end
268
+
269
+ def test_number
270
+ restore(<<-COMMANDS)
271
+ table_create Memos TABLE_HASH_KEY ShortText
272
+ column_create Memos score COLUMN_SCALAR Int32
273
+
274
+ table_create Scores TABLE_PAT_KEY Int32
275
+ column_create Scores memos_score \
276
+ COLUMN_INDEX \
277
+ Memos score
278
+
279
+ load --table Memos
280
+ [
281
+ {"_key": "groonga", "score": 10},
282
+ {"_key": "mroonga", "score": 9}
283
+ ]
284
+
285
+ delete Scores --key 9
286
+ COMMANDS
287
+
288
+ assert_equal([false, "", "Broken: Scores.memos_score: <9>\n"],
289
+ index_check("--method=content"))
290
+ end
291
+ end
292
+ end
@@ -16,82 +16,23 @@
16
16
 
17
17
  require "time"
18
18
 
19
- require "groonga/command/parser"
19
+ require_relative "helper"
20
20
 
21
- require "groonga/client"
22
- require "groonga/client/test-helper"
23
21
  require "groonga/client/command-line/groonga-client-index-recreate"
24
22
 
25
23
  class TestCommandLineIndexRecreate < Test::Unit::TestCase
26
24
  include Groonga::Client::TestHelper
25
+ include CommandLineTestHelper
27
26
 
28
27
  def setup
29
28
  @now = Time.parse("2017-10-25T17:22:00+0900")
30
29
  stub(Time).now {@now}
31
30
  end
32
31
 
33
- def groonga_url
34
- @groonga_server_runner.url.to_s
35
- end
36
-
37
- def open_client
38
- Groonga::Client.open(:url => groonga_url) do |client|
39
- yield(client)
40
- end
41
- end
42
-
43
- def restore(commands)
44
- open_client do |client|
45
- values = nil
46
- Groonga::Command::Parser.parse(commands) do |event, *args|
47
- case event
48
- when :on_command
49
- command, = args
50
- response = client.execute(command)
51
- unless response.success?
52
- raise Groonga::Client::Request::ErrorResponse.new(response)
53
- end
54
- when :on_load_start
55
- command, = args
56
- values = []
57
- when :on_load_columns
58
- command, columns = args
59
- command[:columns] ||= columns.join(",")
60
- when :on_load_value
61
- command, value = args
62
- values << value
63
- when :on_load_complete
64
- command, = args
65
- command[:values] ||= JSON.generate(values)
66
- response = client.execute(command)
67
- unless response.success?
68
- raise Groonga::Client::Request::ErrorResponse.new(response)
69
- end
70
- else
71
- p [:unhandled_event, event, *args]
72
- end
73
- end
74
- end
75
- end
76
-
77
- def dump
78
- open_client do |client|
79
- client.dump.body
80
- end
81
- end
82
-
83
32
  def index_recreate(*arguments)
84
33
  command_line = Groonga::Client::CommandLine::GroongaClientIndexRecreate.new
85
- begin
86
- stdout, $stdout = $stdout, StringIO.new
87
- stderr, $stderr = $stderr, StringIO.new
88
- [
89
- command_line.run(["--url", groonga_url, *arguments]),
90
- $stdout.string,
91
- $stderr.string,
92
- ]
93
- ensure
94
- $stdout, $stderr = stdout, stderr
34
+ capture_outputs do
35
+ command_line.run(["--url", groonga_url, *arguments])
95
36
  end
96
37
  end
97
38
 
@@ -93,6 +93,30 @@ class TestResponseColumnList < Test::Unit::TestCase
93
93
  Groonga::Client::Response::ColumnList.new(@command, header, body)
94
94
  end
95
95
 
96
+ class TestFullName < self
97
+ def create_response(domain, name)
98
+ columns = [
99
+ [
100
+ 256,
101
+ name,
102
+ "/tmp/test.db.0000100",
103
+ "var",
104
+ "COLUMN_SCALAR|PERSISTENT",
105
+ domain,
106
+ "ShortText",
107
+ [],
108
+ ]
109
+ ]
110
+ super(columns)
111
+ end
112
+
113
+ def test_full_name
114
+ response = create_response("Memos", "content")
115
+ assert_equal("Memos.content",
116
+ response[0].full_name)
117
+ end
118
+ end
119
+
96
120
  class TestFlags < self
97
121
  def create_response(flags)
98
122
  columns = [
@@ -137,6 +161,36 @@ class TestResponseColumnList < Test::Unit::TestCase
137
161
  end
138
162
  end
139
163
  end
164
+
165
+ class TestSource < self
166
+ def create_response(sources)
167
+ columns = [
168
+ [
169
+ 256,
170
+ "content",
171
+ "/tmp/test.db.0000100",
172
+ "var",
173
+ "COLUMN_INDEX|WITH_POSITION|PERSISTENT",
174
+ "Memos",
175
+ "ShortText",
176
+ sources,
177
+ ]
178
+ ]
179
+ super(columns)
180
+ end
181
+
182
+ def test_source
183
+ sources = ["Memos.title", "Memos.content"]
184
+ response = create_response(sources)
185
+ assert_equal(sources, response[0].source)
186
+ end
187
+
188
+ def test_sources
189
+ sources = ["Memos.title", "Memos.content"]
190
+ response = create_response(sources)
191
+ assert_equal(sources, response[0].sources)
192
+ end
193
+ end
140
194
  end
141
195
  end
142
196
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-10-27 00:00:00.000000000 Z
13
+ date: 2017-10-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gqtp
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.0.7
49
+ version: 1.1.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 1.0.7
56
+ version: 1.1.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: hashie
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +162,7 @@ email:
162
162
  - tfortress58@gmail.com
163
163
  executables:
164
164
  - groonga-client
165
+ - groonga-client-index-check
165
166
  - groonga-client-index-recreate
166
167
  extensions: []
167
168
  extra_rdoc_files: []
@@ -171,13 +172,17 @@ files:
171
172
  - README.md
172
173
  - Rakefile
173
174
  - bin/groonga-client
175
+ - bin/groonga-client-index-check
174
176
  - bin/groonga-client-index-recreate
175
177
  - doc/text/lgpl-2.1.txt
176
178
  - doc/text/news.md
177
179
  - groonga-client.gemspec
178
180
  - lib/groonga/client.rb
181
+ - lib/groonga/client/command-line/groonga-client-index-check.rb
179
182
  - lib/groonga/client/command-line/groonga-client-index-recreate.rb
180
183
  - lib/groonga/client/command-line/groonga-client.rb
184
+ - lib/groonga/client/command-line/parser.rb
185
+ - lib/groonga/client/command-line/runner.rb
181
186
  - lib/groonga/client/command.rb
182
187
  - lib/groonga/client/default.rb
183
188
  - lib/groonga/client/empty-request.rb
@@ -224,6 +229,8 @@ files:
224
229
  - lib/groonga/client/test/fixture.rb
225
230
  - lib/groonga/client/test/groonga-server-runner.rb
226
231
  - lib/groonga/client/version.rb
232
+ - test/command-line/helper.rb
233
+ - test/command-line/test-index-check.rb
227
234
  - test/command-line/test-index-recreate.rb
228
235
  - test/protocol/test-gqtp.rb
229
236
  - test/protocol/test-http.rb
@@ -274,39 +281,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
281
  version: '0'
275
282
  requirements: []
276
283
  rubyforge_project:
277
- rubygems_version: 2.5.2.1
284
+ rubygems_version: 2.6.13
278
285
  signing_key:
279
286
  specification_version: 4
280
287
  summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
281
288
  with pure Ruby. You can use it without Groonga.
282
289
  test_files:
283
- - test/results/test-table-list.rb
284
- - test/response/test-column-list.rb
285
- - test/response/test-table-remove.rb
286
- - test/response/test-status.rb
287
- - test/response/test-schema.rb
288
- - test/response/helper.rb
289
- - test/response/test-select-xml.rb
290
- - test/response/test-table-create.rb
291
- - test/response/test-select-command-version3.rb
292
- - test/response/test-base.rb
293
- - test/response/test-load.rb
294
- - test/response/test-select-command-version1.rb
295
- - test/response/test-error.rb
296
- - test/response/test-table-list.rb
297
290
  - test/run-test.rb
298
- - test/protocol/test-gqtp.rb
299
- - test/protocol/test-http.rb
300
- - test/test-script-syntax.rb
301
- - test/request/test-generic.rb
302
- - test/request/test-select.rb
291
+ - test/request/select/test-filter.rb
292
+ - test/request/select/test-sort-keys-parameter.rb
303
293
  - test/request/select/test-values-parameter.rb
304
294
  - test/request/select/test-scorer.rb
305
- - test/request/select/test-sort-keys-parameter.rb
306
- - test/request/select/test-filter.rb
307
- - test/request/select/test-backward-compatible-sort-keys-parameter.rb
308
295
  - test/request/select/test-output-columns-parameter.rb
296
+ - test/request/select/test-backward-compatible-sort-keys-parameter.rb
309
297
  - test/request/test-merger.rb
298
+ - test/request/test-select.rb
299
+ - test/request/test-generic.rb
300
+ - test/test-script-syntax.rb
301
+ - test/response/helper.rb
302
+ - test/response/test-table-list.rb
303
+ - test/response/test-status.rb
304
+ - test/response/test-load.rb
305
+ - test/response/test-select-command-version1.rb
306
+ - test/response/test-base.rb
307
+ - test/response/test-table-remove.rb
308
+ - test/response/test-schema.rb
309
+ - test/response/test-column-list.rb
310
+ - test/response/test-table-create.rb
311
+ - test/response/test-select-command-version3.rb
312
+ - test/response/test-select-xml.rb
313
+ - test/response/test-error.rb
314
+ - test/command-line/test-index-check.rb
315
+ - test/command-line/helper.rb
310
316
  - test/command-line/test-index-recreate.rb
311
- - test/test-client.rb
312
317
  - test/test-command.rb
318
+ - test/results/test-table-list.rb
319
+ - test/protocol/test-http.rb
320
+ - test/protocol/test-gqtp.rb
321
+ - test/test-client.rb