Skip to content

Commit 5141f8b

Browse files
committed
Updates elasticsearch helper integration tests
1 parent 0544ce8 commit 5141f8b

File tree

4 files changed

+20
-49
lines changed

4 files changed

+20
-49
lines changed

elasticsearch/spec/integration/helpers/bulk_helper_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
require_relative 'helpers_spec_helper'
17+
require_relative File.expand_path('../../spec_helper'. __dir__)
1818
require 'elasticsearch/helpers/bulk_helper'
1919
require 'tempfile'
2020

@@ -23,7 +23,7 @@
2323
let(:index) { 'bulk_animals' }
2424
let(:index_slice) { 'bulk_animals_slice' }
2525
let(:params) { { refresh: 'wait_for' } }
26-
let(:bulk_helper) { Elasticsearch::Helpers::BulkHelper.new(client, index, params) }
26+
let(:bulk_helper) { Elasticsearch::Helpers::BulkHelper.new(CLIENT, index, params) }
2727
let(:docs) do
2828
[
2929
{ scientific_name: 'Lama guanicoe', name:'Guanaco' },
@@ -40,8 +40,8 @@
4040
end
4141

4242
after do
43-
client.indices.delete(index: index, ignore: 404)
44-
client.indices.delete(index: index_slice, ignore: 404)
43+
CLIENT.indices.delete(index: index, ignore: 404)
44+
CLIENT.indices.delete(index: index_slice, ignore: 404)
4545
end
4646

4747
it 'Ingests documents' do
@@ -58,7 +58,7 @@
5858
]
5959
bulk_helper.ingest(docs)
6060
# Get the ingested documents, add id and modify them to update them:
61-
animals = client.search(index: index)['hits']['hits']
61+
animals = CLIENT.search(index: index)['hits']['hits']
6262
# Add id to each doc
6363
docs = animals.map { |animal| animal['_source'].merge({'id' => animal['_id'] }) }
6464
docs.map { |doc| doc['scientific_name'].upcase! }
@@ -73,17 +73,17 @@
7373
response = bulk_helper.delete(ids)
7474
expect(response.status).to eq 200
7575
expect(response['items'].map { |item| item['delete']['result'] }.uniq.first).to eq('deleted')
76-
expect(client.count(index: index)['count']).to eq(0)
76+
expect(CLIENT.count(index: index)['count']).to eq(0)
7777
end
7878

7979
it 'Ingests documents and yields response and docs' do
8080
slice = 2
81-
bulk_helper = Elasticsearch::Helpers::BulkHelper.new(client, index_slice, params)
81+
bulk_helper = Elasticsearch::Helpers::BulkHelper.new(CLIENT, index_slice, params)
8282
response = bulk_helper.ingest(docs, {slice: slice}) do |response, docs|
8383
expect(response).to be_an_instance_of Elasticsearch::API::Response
8484
expect(docs.count).to eq slice
8585
end
86-
response = client.search(index: index_slice, size: 200)
86+
response = CLIENT.search(index: index_slice, size: 200)
8787
expect(response['hits']['hits'].map { |a| a['_source'].transform_keys(&:to_sym) }).to eq docs
8888
end
8989

elasticsearch/spec/integration/helpers/esql_helper_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
require_relative 'helpers_spec_helper'
17+
require_relative File.expand_path('../../spec_helper'. __dir__)
1818
require 'elasticsearch/helpers/esql_helper'
1919
require 'ipaddr'
2020

@@ -30,15 +30,15 @@
3030
end
3131

3232
before do
33-
client.indices.create(
33+
CLIENT.indices.create(
3434
index: index,
3535
body: {
3636
mappings: {
3737
properties: { 'client.ip' => { type: 'ip' }, message: { type: 'keyword' } }
3838
}
3939
}
4040
)
41-
client.bulk(
41+
CLIENT.bulk(
4242
index: index,
4343
body: [
4444
{'index': {}},
@@ -61,11 +61,11 @@
6161
end
6262

6363
after do
64-
client.indices.delete(index: index)
64+
CLIENT.indices.delete(index: index)
6565
end
6666

6767
it 'returns an ESQL response as a relational key/value object' do
68-
response = esql_helper.query(client, query)
68+
response = esql_helper.query(CLIENT, query)
6969
expect(response.count).to eq 7
7070
expect(response.first.keys).to eq ['duration_ms', 'message', 'event.duration', 'client.ip', '@timestamp']
7171
response.each do |r|
@@ -82,7 +82,7 @@
8282
'client.ip' => Proc.new { |i| IPAddr.new(i) },
8383
'event.duration' => Proc.new { |d| d.to_s }
8484
}
85-
response = esql_helper.query(client, query, parser: parser)
85+
response = esql_helper.query(CLIENT, query, parser: parser)
8686
response.each do |r|
8787
expect(r['@timestamp']).to be_a DateTime
8888
expect(r['client.ip']).to be_a IPAddr
@@ -92,7 +92,7 @@
9292
end
9393

9494
it 'parser does not error when value is nil, leaves nil' do
95-
client.index(
95+
CLIENT.index(
9696
index: index,
9797
body: {
9898
'@timestamp' => nil,
@@ -107,7 +107,7 @@
107107
'client.ip' => Proc.new { |i| IPAddr.new(i) },
108108
'event.duration' => Proc.new { |d| d.to_s }
109109
}
110-
response = esql_helper.query(client, query, parser: parser)
110+
response = esql_helper.query(CLIENT, query, parser: parser)
111111
response.each do |r|
112112
expect [DateTime, NilClass].include?(r['@timestamp'].class)
113113
expect [IPAddr, NilClass].include?(r['client.ip'].class)

elasticsearch/spec/integration/helpers/helpers_spec_helper.rb

Lines changed: 0 additions & 29 deletions
This file was deleted.

elasticsearch/spec/integration/helpers/scroll_helper_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
require_relative 'helpers_spec_helper'
17+
require_relative File.expand_path('../../spec_helper'. __dir__)
1818
require 'elasticsearch/helpers/scroll_helper'
1919

2020
context 'Elasticsearch client helpers' do
2121
context 'ScrollHelper' do
2222
let(:index) { 'books' }
2323
let(:body) { { size: 12, query: { match_all: {} } } }
24-
let(:scroll_helper) { Elasticsearch::Helpers::ScrollHelper.new(client, index, body) }
24+
let(:scroll_helper) { Elasticsearch::Helpers::ScrollHelper.new(CLIENT, index, body) }
2525

2626
before do
2727
documents = [
@@ -50,11 +50,11 @@
5050
{ index: { _index: index, data: {name: "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304} } },
5151
{ index: { _index: index, data: {name: "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288 } } }
5252
]
53-
client.bulk(body: documents, refresh: 'wait_for')
53+
CLIENT.bulk(body: documents, refresh: 'wait_for')
5454
end
5555

5656
after do
57-
client.indices.delete(index: index)
57+
CLIENT.indices.delete(index: index)
5858
end
5959

6060
it 'instantiates a scroll helper' do

0 commit comments

Comments
 (0)