elasticsearch 7.1.0 → 8.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -16
- data/Gemfile +5 -11
- data/README.md +71 -49
- data/Rakefile +16 -22
- data/bin/elastic_ruby_console +2 -18
- data/elasticsearch.gemspec +34 -56
- data/lib/elasticsearch/helpers/bulk_helper.rb +127 -0
- data/lib/elasticsearch/helpers/scroll_helper.rb +95 -0
- data/lib/elasticsearch/version.rb +2 -2
- data/lib/elasticsearch-ruby.rb +1 -1
- data/lib/elasticsearch.rb +178 -7
- data/spec/integration/characters_escaping_spec.rb +94 -0
- data/spec/integration/client_integration_spec.rb +63 -0
- data/spec/integration/helpers/bulk_helper_spec.rb +211 -0
- data/spec/integration/helpers/scroll_helper_spec.rb +91 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/unit/api_key_spec.rb +137 -0
- data/spec/unit/cloud_credentials_spec.rb +167 -0
- data/spec/unit/custom_transport_implementation_spec.rb +43 -0
- data/spec/unit/elasticsearch_product_validation_spec.rb +148 -0
- data/spec/unit/headers_spec.rb +55 -0
- data/spec/unit/opaque_id_spec.rb +48 -0
- data/spec/unit/user_agent_spec.rb +69 -0
- data/{test/unit/wrapper_gem_test.rb → spec/unit/wrapper_gem_spec.rb} +12 -22
- metadata +55 -111
- data/test/integration/client_integration_test.rb +0 -76
- data/test/test_helper.rb +0 -115
@@ -0,0 +1,48 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
require 'spec_helper'
|
18
|
+
require 'ostruct'
|
19
|
+
|
20
|
+
describe Elasticsearch::Client do
|
21
|
+
let(:transport) { client.instance_variable_get('@transport') }
|
22
|
+
let(:client) { described_class.new.tap { |cl| cl.instance_variable_set('@verified', true) } }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(transport).to receive(:perform_request) { OpenStruct.new(body: '') }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when x-opaque-id is set' do
|
29
|
+
it 'uses x-opaque-id on a request' do
|
30
|
+
client.search(opaque_id: '12345')
|
31
|
+
expect(transport).to have_received(:perform_request)
|
32
|
+
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when an x-opaque-id prefix is set on initialization' do
|
37
|
+
let(:prefix) { 'elastic_cloud' }
|
38
|
+
let(:client) do
|
39
|
+
described_class.new(opaque_id_prefix: prefix).tap { |cl| cl.instance_variable_set('@verified', true) }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'uses x-opaque-id on a request' do
|
43
|
+
expect { client.search(opaque_id: '12345') }.not_to raise_error
|
44
|
+
expect(transport).to have_received(:perform_request)
|
45
|
+
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' })
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe Elasticsearch::Client do
|
20
|
+
let(:user_agent) {
|
21
|
+
"elasticsearch-ruby/#{Elasticsearch::VERSION}; elastic-transport-ruby/#{Elastic::Transport::VERSION}; RUBY_VERSION: #{RUBY_VERSION}; #{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
22
|
+
}
|
23
|
+
|
24
|
+
context 'when no user-agent is set on initialization' do
|
25
|
+
let(:client) { described_class.new }
|
26
|
+
|
27
|
+
it 'has the expected header' do
|
28
|
+
expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq user_agent
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when a header is specified on initialization' do
|
33
|
+
let(:client) do
|
34
|
+
described_class.new(
|
35
|
+
transport_options: { headers: { 'X-Test-Header' => 'Test' } }
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'has the expected header' do
|
40
|
+
expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq user_agent
|
41
|
+
expect(client.transport.options[:transport_options][:headers]['X-Test-Header']).to eq 'Test'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when other transport_options are specified on initialization' do
|
46
|
+
let(:client) do
|
47
|
+
described_class.new(
|
48
|
+
transport_options: { params: { format: 'yaml' } }
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'has the expected header' do
|
53
|
+
expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq user_agent
|
54
|
+
expect(client.transport.options[:transport_options][:params][:format]).to eq 'yaml'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when :user_agent is specified on initialization' do
|
59
|
+
let(:client) do
|
60
|
+
described_class.new(
|
61
|
+
transport_options: { headers: { user_agent: 'TestApp' } }
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'has the expected header' do
|
66
|
+
expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq 'TestApp'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -15,29 +15,19 @@
|
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'spec_helper'
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
should "require all neccessary subgems" do
|
27
|
-
assert defined? Elasticsearch::Client
|
28
|
-
assert defined? Elasticsearch::API
|
29
|
-
end
|
30
|
-
|
31
|
-
should "mix the API into the client" do
|
32
|
-
client = Elasticsearch::Client.new
|
33
|
-
|
34
|
-
assert_respond_to client, :search
|
35
|
-
assert_respond_to client, :cluster
|
36
|
-
assert_respond_to client, :indices
|
37
|
-
end
|
20
|
+
describe 'Elasticsearch: wrapper gem' do
|
21
|
+
it 'requires all neccessary subgems' do
|
22
|
+
expect(defined? Elasticsearch::Client)
|
23
|
+
expect(defined? Elasticsearch::API)
|
24
|
+
end
|
38
25
|
|
39
|
-
|
26
|
+
it 'mixes the API into the client' do
|
27
|
+
client = Elasticsearch::Client.new
|
40
28
|
|
41
|
-
|
29
|
+
expect(client).to respond_to(:search)
|
30
|
+
expect(client).to respond_to(:cluster)
|
31
|
+
expect(client).to respond_to(:indices)
|
42
32
|
end
|
43
33
|
end
|
metadata
CHANGED
@@ -1,43 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
|
+
- Emily Stolfo
|
9
|
+
- Fernando Briano
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2023-09-12 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
16
|
+
name: elastic-transport
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - "~>"
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
21
|
+
version: '8'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- -
|
26
|
+
- - "~>"
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
28
|
+
version: '8'
|
27
29
|
- !ruby/object:Gem::Dependency
|
28
30
|
name: elasticsearch-api
|
29
31
|
requirement: !ruby/object:Gem::Requirement
|
30
32
|
requirements:
|
31
33
|
- - '='
|
32
34
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
35
|
+
version: 8.10.0
|
34
36
|
type: :runtime
|
35
37
|
prerelease: false
|
36
38
|
version_requirements: !ruby/object:Gem::Requirement
|
37
39
|
requirements:
|
38
40
|
- - '='
|
39
41
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
42
|
+
version: 8.10.0
|
41
43
|
- !ruby/object:Gem::Dependency
|
42
44
|
name: bundler
|
43
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,77 +55,7 @@ dependencies:
|
|
53
55
|
- !ruby/object:Gem::Version
|
54
56
|
version: '0'
|
55
57
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '11.1'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '11.1'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: elasticsearch-extensions
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: ansi
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: shoulda-context
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: mocha
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: yard
|
58
|
+
name: byebug
|
127
59
|
requirement: !ruby/object:Gem::Requirement
|
128
60
|
requirements:
|
129
61
|
- - ">="
|
@@ -151,7 +83,7 @@ dependencies:
|
|
151
83
|
- !ruby/object:Gem::Version
|
152
84
|
version: '0'
|
153
85
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
86
|
+
name: rake
|
155
87
|
requirement: !ruby/object:Gem::Requirement
|
156
88
|
requirements:
|
157
89
|
- - ">="
|
@@ -165,7 +97,7 @@ dependencies:
|
|
165
97
|
- !ruby/object:Gem::Version
|
166
98
|
version: '0'
|
167
99
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
100
|
+
name: require-prof
|
169
101
|
requirement: !ruby/object:Gem::Requirement
|
170
102
|
requirements:
|
171
103
|
- - ">="
|
@@ -179,7 +111,7 @@ dependencies:
|
|
179
111
|
- !ruby/object:Gem::Version
|
180
112
|
version: '0'
|
181
113
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
114
|
+
name: rspec
|
183
115
|
requirement: !ruby/object:Gem::Requirement
|
184
116
|
requirements:
|
185
117
|
- - ">="
|
@@ -193,7 +125,7 @@ dependencies:
|
|
193
125
|
- !ruby/object:Gem::Version
|
194
126
|
version: '0'
|
195
127
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
128
|
+
name: ruby-prof
|
197
129
|
requirement: !ruby/object:Gem::Requirement
|
198
130
|
requirements:
|
199
131
|
- - ">="
|
@@ -221,7 +153,7 @@ dependencies:
|
|
221
153
|
- !ruby/object:Gem::Version
|
222
154
|
version: '0'
|
223
155
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
156
|
+
name: webmock
|
225
157
|
requirement: !ruby/object:Gem::Requirement
|
226
158
|
requirements:
|
227
159
|
- - ">="
|
@@ -235,7 +167,7 @@ dependencies:
|
|
235
167
|
- !ruby/object:Gem::Version
|
236
168
|
version: '0'
|
237
169
|
- !ruby/object:Gem::Dependency
|
238
|
-
name:
|
170
|
+
name: yard
|
239
171
|
requirement: !ruby/object:Gem::Requirement
|
240
172
|
requirements:
|
241
173
|
- - ">="
|
@@ -248,25 +180,11 @@ dependencies:
|
|
248
180
|
- - ">="
|
249
181
|
- !ruby/object:Gem::Version
|
250
182
|
version: '0'
|
251
|
-
- !ruby/object:Gem::Dependency
|
252
|
-
name: test-unit
|
253
|
-
requirement: !ruby/object:Gem::Requirement
|
254
|
-
requirements:
|
255
|
-
- - "~>"
|
256
|
-
- !ruby/object:Gem::Version
|
257
|
-
version: '2'
|
258
|
-
type: :development
|
259
|
-
prerelease: false
|
260
|
-
version_requirements: !ruby/object:Gem::Requirement
|
261
|
-
requirements:
|
262
|
-
- - "~>"
|
263
|
-
- !ruby/object:Gem::Version
|
264
|
-
version: '2'
|
265
183
|
description: 'Ruby integrations for Elasticsearch (client, API, etc.)
|
266
184
|
|
267
185
|
'
|
268
186
|
email:
|
269
|
-
-
|
187
|
+
- clients-team@elastic.co
|
270
188
|
executables:
|
271
189
|
- elastic_ruby_console
|
272
190
|
extensions: []
|
@@ -283,14 +201,30 @@ files:
|
|
283
201
|
- elasticsearch.gemspec
|
284
202
|
- lib/elasticsearch-ruby.rb
|
285
203
|
- lib/elasticsearch.rb
|
204
|
+
- lib/elasticsearch/helpers/bulk_helper.rb
|
205
|
+
- lib/elasticsearch/helpers/scroll_helper.rb
|
286
206
|
- lib/elasticsearch/version.rb
|
287
|
-
-
|
288
|
-
-
|
289
|
-
-
|
290
|
-
|
207
|
+
- spec/integration/characters_escaping_spec.rb
|
208
|
+
- spec/integration/client_integration_spec.rb
|
209
|
+
- spec/integration/helpers/bulk_helper_spec.rb
|
210
|
+
- spec/integration/helpers/scroll_helper_spec.rb
|
211
|
+
- spec/spec_helper.rb
|
212
|
+
- spec/unit/api_key_spec.rb
|
213
|
+
- spec/unit/cloud_credentials_spec.rb
|
214
|
+
- spec/unit/custom_transport_implementation_spec.rb
|
215
|
+
- spec/unit/elasticsearch_product_validation_spec.rb
|
216
|
+
- spec/unit/headers_spec.rb
|
217
|
+
- spec/unit/opaque_id_spec.rb
|
218
|
+
- spec/unit/user_agent_spec.rb
|
219
|
+
- spec/unit/wrapper_gem_spec.rb
|
220
|
+
homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
|
291
221
|
licenses:
|
292
222
|
- Apache-2.0
|
293
|
-
metadata:
|
223
|
+
metadata:
|
224
|
+
homepage_uri: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
|
225
|
+
changelog_uri: https://github.com/elastic/elasticsearch-ruby/blob/main/CHANGELOG.md
|
226
|
+
source_code_uri: https://github.com/elastic/elasticsearch-ruby/tree/main
|
227
|
+
bug_tracker_uri: https://github.com/elastic/elasticsearch-ruby/issues
|
294
228
|
post_install_message:
|
295
229
|
rdoc_options:
|
296
230
|
- "--charset=UTF-8"
|
@@ -300,18 +234,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
300
234
|
requirements:
|
301
235
|
- - ">="
|
302
236
|
- !ruby/object:Gem::Version
|
303
|
-
version: '
|
237
|
+
version: '2.5'
|
304
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
305
239
|
requirements:
|
306
240
|
- - ">="
|
307
241
|
- !ruby/object:Gem::Version
|
308
242
|
version: '0'
|
309
243
|
requirements: []
|
310
|
-
rubygems_version: 3.
|
244
|
+
rubygems_version: 3.4.19
|
311
245
|
signing_key:
|
312
246
|
specification_version: 4
|
313
247
|
summary: Ruby integrations for Elasticsearch
|
314
248
|
test_files:
|
315
|
-
-
|
316
|
-
-
|
317
|
-
-
|
249
|
+
- spec/integration/characters_escaping_spec.rb
|
250
|
+
- spec/integration/client_integration_spec.rb
|
251
|
+
- spec/integration/helpers/bulk_helper_spec.rb
|
252
|
+
- spec/integration/helpers/scroll_helper_spec.rb
|
253
|
+
- spec/spec_helper.rb
|
254
|
+
- spec/unit/api_key_spec.rb
|
255
|
+
- spec/unit/cloud_credentials_spec.rb
|
256
|
+
- spec/unit/custom_transport_implementation_spec.rb
|
257
|
+
- spec/unit/elasticsearch_product_validation_spec.rb
|
258
|
+
- spec/unit/headers_spec.rb
|
259
|
+
- spec/unit/opaque_id_spec.rb
|
260
|
+
- spec/unit/user_agent_spec.rb
|
261
|
+
- spec/unit/wrapper_gem_spec.rb
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
-
# license agreements. See the NOTICE file distributed with
|
3
|
-
# this work for additional information regarding copyright
|
4
|
-
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
-
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
-
# not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
12
|
-
# software distributed under the License is distributed on an
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
-
# KIND, either express or implied. See the License for the
|
15
|
-
# specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
|
18
|
-
require 'test_helper'
|
19
|
-
require 'logger'
|
20
|
-
|
21
|
-
module Elasticsearch
|
22
|
-
module Test
|
23
|
-
class ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
24
|
-
startup do
|
25
|
-
Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 2) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
|
26
|
-
end
|
27
|
-
|
28
|
-
shutdown do
|
29
|
-
Elasticsearch::Extensions::Test::Cluster.stop(number_of_nodes: 2) if ENV['SERVER'] and Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
|
30
|
-
end
|
31
|
-
|
32
|
-
context "Elasticsearch client" do
|
33
|
-
setup do
|
34
|
-
system "curl -X DELETE http://#{TEST_HOST}:#{TEST_PORT}/_all > /dev/null 2>&1"
|
35
|
-
|
36
|
-
@logger = Logger.new(STDERR)
|
37
|
-
@logger.formatter = proc do |severity, datetime, progname, msg|
|
38
|
-
color = case severity
|
39
|
-
when /INFO/ then :green
|
40
|
-
when /ERROR|WARN|FATAL/ then :red
|
41
|
-
when /DEBUG/ then :cyan
|
42
|
-
else :white
|
43
|
-
end
|
44
|
-
ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
|
45
|
-
end
|
46
|
-
|
47
|
-
@client = Elasticsearch::Client.new host: "#{TEST_HOST}:#{TEST_PORT}", logger: (ENV['QUIET'] ? nil : @logger)
|
48
|
-
end
|
49
|
-
|
50
|
-
should "perform the API methods" do
|
51
|
-
assert_nothing_raised do
|
52
|
-
# Index a document
|
53
|
-
#
|
54
|
-
@client.index index: 'test-index', type: 'test-type', id: '1', body: { title: 'Test' }
|
55
|
-
|
56
|
-
# Refresh the index
|
57
|
-
#
|
58
|
-
@client.indices.refresh index: 'test-index'
|
59
|
-
|
60
|
-
# Search
|
61
|
-
#
|
62
|
-
response = @client.search index: 'test-index', body: { query: { match: { title: 'test' } } }
|
63
|
-
|
64
|
-
assert_equal 1, response['hits']['total']['value']
|
65
|
-
assert_equal 'Test', response['hits']['hits'][0]['_source']['title']
|
66
|
-
|
67
|
-
# Delete the index
|
68
|
-
#
|
69
|
-
@client.indices.delete index: 'test-index'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
-
# license agreements. See the NOTICE file distributed with
|
3
|
-
# this work for additional information regarding copyright
|
4
|
-
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
-
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
-
# not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
12
|
-
# software distributed under the License is distributed on an
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
-
# KIND, either express or implied. See the License for the
|
15
|
-
# specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
|
18
|
-
ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
|
19
|
-
hosts.split(',').map do |host|
|
20
|
-
/(http\:\/\/)?(\S+)/.match(host)[2]
|
21
|
-
end
|
22
|
-
end.freeze
|
23
|
-
|
24
|
-
TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
|
25
|
-
|
26
|
-
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
27
|
-
JRUBY = defined?(JRUBY_VERSION)
|
28
|
-
|
29
|
-
if RUBY_1_8 and not ENV['BUNDLE_GEMFILE']
|
30
|
-
require 'rubygems'
|
31
|
-
gem 'test-unit'
|
32
|
-
end
|
33
|
-
|
34
|
-
if ENV['COVERAGE'] && ENV['CI'].nil? && !RUBY_1_8
|
35
|
-
require 'simplecov'
|
36
|
-
SimpleCov.start { add_filter "/test|test_/" }
|
37
|
-
end
|
38
|
-
|
39
|
-
if ENV['CI'] && !RUBY_1_8
|
40
|
-
require 'simplecov'
|
41
|
-
require 'simplecov-rcov'
|
42
|
-
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
43
|
-
SimpleCov.start { add_filter "/test|test_" }
|
44
|
-
end
|
45
|
-
|
46
|
-
# Register `at_exit` handler for integration tests shutdown.
|
47
|
-
# MUST be called before requiring `test/unit`.
|
48
|
-
if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
49
|
-
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
|
50
|
-
end
|
51
|
-
|
52
|
-
require 'test/unit' if RUBY_1_8
|
53
|
-
|
54
|
-
require 'minitest/autorun'
|
55
|
-
require 'minitest/reporters'
|
56
|
-
require 'shoulda/context'
|
57
|
-
require 'mocha/minitest'
|
58
|
-
|
59
|
-
require 'require-prof' if ENV["REQUIRE_PROF"]
|
60
|
-
require 'elasticsearch'
|
61
|
-
RequireProf.print_timing_infos if ENV["REQUIRE_PROF"]
|
62
|
-
|
63
|
-
if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
64
|
-
require 'elasticsearch/extensions/test/cluster'
|
65
|
-
require 'elasticsearch/extensions/test/startup_shutdown'
|
66
|
-
require 'elasticsearch/extensions/test/profiling' unless JRUBY
|
67
|
-
end
|
68
|
-
|
69
|
-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
70
|
-
|
71
|
-
module Minitest
|
72
|
-
module Assertions
|
73
|
-
def assert_nothing_raised(*args)
|
74
|
-
begin
|
75
|
-
line = __LINE__
|
76
|
-
yield
|
77
|
-
rescue RuntimeError => e
|
78
|
-
raise MiniTest::Assertion, "Exception raised:\n<#{e.class}>", e.backtrace
|
79
|
-
end
|
80
|
-
true
|
81
|
-
end
|
82
|
-
|
83
|
-
def assert_not_nil(object, msg=nil)
|
84
|
-
msg = message(msg) { "<#{object.inspect}> expected to not be nil" }
|
85
|
-
assert !object.nil?, msg
|
86
|
-
end
|
87
|
-
|
88
|
-
def assert_block(*msgs)
|
89
|
-
assert yield, *msgs
|
90
|
-
end
|
91
|
-
|
92
|
-
alias :assert_raise :assert_raises
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
module Elasticsearch
|
97
|
-
module Test
|
98
|
-
class IntegrationTestCase < ::Minitest::Test
|
99
|
-
extend Elasticsearch::Extensions::Test::StartupShutdown
|
100
|
-
|
101
|
-
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
102
|
-
context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
|
103
|
-
end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
104
|
-
end
|
105
|
-
|
106
|
-
module Test
|
107
|
-
class ProfilingTest < ::Minitest::Test
|
108
|
-
extend Elasticsearch::Extensions::Test::StartupShutdown
|
109
|
-
extend Elasticsearch::Extensions::Test::Profiling
|
110
|
-
|
111
|
-
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
112
|
-
context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
|
113
|
-
end unless RUBY_1_8 || JRUBY
|
114
|
-
end
|
115
|
-
end
|