Skip to content

Commit

Permalink
feat: fix specs for es that use type
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 2, 2024
1 parent 4b841a6 commit 7d469ed
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
require 'support/shared_examples/transport_update_by_query'

stack_describe 'elasticsearch', '5.x', Esse::Transport, '#update_by_query' do
include_examples 'transport#update_by_query'
include_examples 'transport#update_by_query', doc_type: true
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
require 'support/shared_examples/transport_update_by_query'

stack_describe 'elasticsearch', '6.x', Esse::Transport, '#update_by_query' do
include_examples 'transport#update_by_query'
include_examples 'transport#update_by_query', doc_type: true
end
13 changes: 8 additions & 5 deletions spec/support/shared_examples/transport_update_by_query.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

RSpec.shared_examples 'transport#update_by_query' do
RSpec.shared_examples 'transport#update_by_query' do |doc_type: false|
let(:params) do
doc_type ? { type: 'geo' } : {}
end
let(:body) do
{
settings: {
Expand All @@ -18,15 +21,15 @@
expect(client).not_to receive(:perform_request)
cluster.readonly = true
expect {
cluster.api.update_by_query(index: "#{cluster.index_prefix}_redonly", body: { script: { source: 'ctx._source.title = "foo"' } }, q: '*')
cluster.api.update_by_query(**params, index: "#{cluster.index_prefix}_redonly", body: { script: { source: 'ctx._source.title = "foo"' } }, q: '*')
}.to raise_error(Esse::Transport::ReadonlyClusterError)
end
end

it 'raises an #<Esse::Transport::NotFoundError exception when the source index does not exist' do
es_client do |_client, _conf, cluster|
expect {
cluster.api.update_by_query(index: "#{cluster.index_prefix}_non_existent_index", body: { script: { source: 'ctx._source.title = "foo"' }, query: { match_all: {} } })
cluster.api.update_by_query(**params, index: "#{cluster.index_prefix}_non_existent_index", body: { script: { source: 'ctx._source.title = "foo"' }, query: { match_all: {} } })
}.to raise_error(Esse::Transport::NotFoundError)
end
end
Expand All @@ -36,11 +39,11 @@
es_client do |client, _conf, cluster|
index_name = "#{cluster.index_prefix}_update_by_query"
cluster.api.create_index(index: index_name, body: body)
cluster.api.index(index: index_name, id: 1, body: { title: 'old title' }, refresh: true)
cluster.api.index(**params, index: index_name, id: 1, body: { title: 'old title' }, refresh: true)

resp = nil
expect {
resp = cluster.api.update_by_query(index: index_name, body: { script: { source: 'ctx._source.title = "new title"' }, query: { match_all: {} } })
resp = cluster.api.update_by_query(**params, index: index_name, body: { script: { source: 'ctx._source.title = "new title"' }, query: { match_all: {} } })
}.not_to raise_error
expect(resp['total']).to eq(1)
expect(resp['updated']).to eq(1)
Expand Down

0 comments on commit 7d469ed

Please sign in to comment.