Skip to content

Commit d2ed3fc

Browse files
committed
[API][Tests] Updates unit tests for API and perform_request_spec
1 parent 1b9c9ec commit d2ed3fc

14 files changed

+49
-179
lines changed

elasticsearch-api/spec/unit/actions/clear_scroll_spec.rb

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,15 @@
2222
let(:expected_args) do
2323
[
2424
'DELETE',
25-
'_search/scroll/abc123',
25+
'_search/scroll',
2626
{},
27-
nil,
27+
{ scroll_id: 'abc123' },
2828
{},
29-
{ defined_params: { scroll_id: 'abc123' }, endpoint: 'clear_scroll' }
29+
{ endpoint: 'clear_scroll' }
3030
]
3131
end
3232

3333
it 'performs the request' do
34-
expect(client_double.clear_scroll(scroll_id: 'abc123')).to be_a Elasticsearch::API::Response
35-
end
36-
37-
context 'when a list of scroll ids is provided' do
38-
39-
let(:expected_args) do
40-
[
41-
'DELETE',
42-
'_search/scroll/abc123,def456',
43-
{},
44-
nil,
45-
{},
46-
{ defined_params: { scroll_id: ['abc123', 'def456'] }, endpoint: 'clear_scroll' }
47-
]
48-
end
49-
50-
it 'performs the request' do
51-
expect(client_double.clear_scroll(scroll_id: ['abc123', 'def456'])).to be_a Elasticsearch::API::Response
52-
end
34+
expect(client_double.clear_scroll(body: { scroll_id: 'abc123' })).to be_a Elasticsearch::API::Response
5335
end
5436
end

elasticsearch-api/spec/unit/actions/cluster/reroute_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
let(:expected_args) do
2323
[
24-
'POST',
25-
'_cluster/reroute',
26-
{},
27-
{},
28-
{},
29-
{ endpoint: 'cluster.reroute' }
24+
'POST',
25+
'_cluster/reroute',
26+
{},
27+
nil,
28+
{},
29+
{ endpoint: 'cluster.reroute' }
3030
]
3131
end
3232

@@ -38,12 +38,12 @@
3838

3939
let(:expected_args) do
4040
[
41-
'POST',
42-
'_cluster/reroute',
43-
{},
44-
{ commands: [ move: { index: 'myindex', shard: 0 }] },
45-
{},
46-
{ endpoint: 'cluster.reroute' }
41+
'POST',
42+
'_cluster/reroute',
43+
{},
44+
{ commands: [ move: { index: 'myindex', shard: 0 }] },
45+
{},
46+
{ endpoint: 'cluster.reroute' }
4747
]
4848
end
4949

elasticsearch-api/spec/unit/actions/indices/get_field_mapping_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{},
2727
nil,
2828
{},
29-
{ endpoint: 'indices.get_field_mapping' }
29+
{ endpoint: 'indices.get_field_mapping', defined_params: { fields: 'foo' } }
3030
]
3131
end
3232

@@ -35,11 +35,10 @@
3535
end
3636

3737
it 'performs the request' do
38-
expect(client_double.indices.get_field_mapping(field: 'foo')).to be_a Elasticsearch::API::Response
38+
expect(client_double.indices.get_field_mapping(fields: 'foo')).to be_a Elasticsearch::API::Response
3939
end
4040

4141
context 'when an index is specified' do
42-
4342
let(:url) do
4443
'foo/_mapping/field/bam'
4544
end
@@ -51,12 +50,12 @@
5150
{},
5251
nil,
5352
{},
54-
{ defined_params: { index: 'foo' }, endpoint: 'indices.get_field_mapping' }
53+
{ defined_params: { index: 'foo', fields: 'bam' }, endpoint: 'indices.get_field_mapping' }
5554
]
5655
end
5756

5857
it 'performs the request' do
59-
expect(client_double.indices.get_field_mapping(index: 'foo', field: 'bam')).to be_a Elasticsearch::API::Response
58+
expect(client_double.indices.get_field_mapping(index: 'foo', fields: 'bam')).to be_a Elasticsearch::API::Response
6059
end
6160
end
6261
end

elasticsearch-api/spec/unit/actions/indices/resolve_cluster_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@
3030
]
3131
end
3232

33-
context 'when there is no name specified' do
34-
let(:client) do
35-
Class.new { include Elasticsearch::API }.new
36-
end
37-
38-
it 'raises an exception' do
39-
expect {
40-
client.indices.resolve_cluster
41-
}.to raise_exception(ArgumentError)
42-
end
43-
end
44-
45-
4633
context 'when name is specified' do
4734
it 'performs the request' do
4835
expect(client_double.indices.resolve_cluster(name: 'foo')).to be_a Elasticsearch::API::Response

elasticsearch-api/spec/unit/actions/inference/inference_spec.rb

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

elasticsearch-api/spec/unit/actions/inference/put_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
let(:expected_args) do
2222
[
2323
'PUT',
24-
'_inference/foo/bar',
24+
'_inference/bar',
2525
{},
26-
nil,
2726
{},
28-
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
27+
{},
28+
{ defined_params: { inference_id: 'bar' },
2929
endpoint: 'inference.put' }
3030
]
3131
end
3232

3333
it 'performs the request' do
34-
expect(client_double.inference.put(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
34+
expect(client_double.inference.put(body: {}, inference_id: 'bar')).to be_a Elasticsearch::API::Response
3535
end
3636
end

elasticsearch-api/spec/unit/actions/inference/stream_inference_spec.rb

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

elasticsearch-api/spec/unit/actions/inference/unified_inference_spec.rb

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

elasticsearch-api/spec/unit/actions/inference/update_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
'PUT',
2424
'_inference/foo/bar/_update',
2525
{},
26-
nil,
26+
{},
2727
{},
2828
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
2929
endpoint: 'inference.update' }
3030
]
3131
end
3232

3333
it 'performs the request' do
34-
expect(client_double.inference.update(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
34+
expect(client_double.inference.update(task_type: 'foo', body: {}, inference_id: 'bar')).to be_a Elasticsearch::API::Response
3535
end
3636
end

elasticsearch-api/spec/unit/actions/ingest/get_ip_location_database_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
[
2323
'GET',
2424
'_ingest/ip_location/database/foo',
25-
{},
25+
{ body: {}},
2626
nil,
2727
{},
2828
{ defined_params: { id: 'foo' }, endpoint: 'ingest.get_ip_location_database' }

elasticsearch-api/spec/unit/actions/machine_learning/infer_trained_model_deployment_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
let(:expected_args) do
2222
[
2323
'POST',
24-
'_ml/trained_models/foo/deployment/_infer',
24+
'_ml/trained_models/foo/_infer',
2525
{},
2626
{},
2727
{},

elasticsearch-api/spec/unit/actions/mtermvectors_spec.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,28 @@
2323
'POST',
2424
'my-index/_mtermvectors',
2525
{},
26-
body,
26+
{ ids: [1,2,3] },
2727
{},
2828
{ defined_params: { index: 'my-index' }, endpoint: 'mtermvectors' }
2929
]
3030
end
3131

32-
let(:body) do
33-
{ ids: [1, 2, 3] }
34-
end
35-
3632
it 'performs the request' do
3733
expect(client_double.mtermvectors(index: 'my-index', body: { ids: [1, 2, 3] })).to be_a Elasticsearch::API::Response
3834
end
3935

4036
context 'when a list of ids is passed instead of a body' do
37+
let(:expected_args) do
38+
[
39+
'GET',
40+
'my-index/_mtermvectors',
41+
{ids: '1,2,3'},
42+
nil,
43+
{},
44+
{ defined_params: { index: 'my-index' }, endpoint: 'mtermvectors' }
45+
]
46+
end
47+
4148
it 'performs the request' do
4249
expect(client_double.mtermvectors(index: 'my-index', ids: [1, 2, 3])).to be_a Elasticsearch::API::Response
4350
end

elasticsearch-api/spec/unit/actions/scroll_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
let(:expected_args) do
2323
[
2424
'GET',
25-
'_search/scroll/cXVlcn...',
25+
'_search/scroll',
2626
{},
2727
nil,
2828
{},
29-
{ defined_params: { scroll_id: 'cXVlcn...' }, endpoint: 'scroll' }
29+
{ endpoint: 'scroll' }
3030
]
3131
end
3232

elasticsearch-api/spec/unit/perform_request_spec.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
describe 'Perform request args' do
2424
Elasticsearch::API::FilesHelper.files.each do |filepath|
2525
spec = Elasticsearch::API::EndpointSpec.new(filepath)
26-
next if spec.module_namespace.flatten.first == '_internal' || spec.visibility != 'public'
26+
next if spec.module_namespace.flatten.first == '_internal' ||
27+
spec.visibility != 'public' ||
28+
# TODO: Once the test suite is migrated to elasticsearch-specification, these should be removed
29+
spec.module_namespace.flatten.first == 'rollup' ||
30+
['scroll', 'clear_scroll', 'connector.last_sync'].include?(spec.endpoint_name)
2731

2832
# These are the path parts defined by the user in the method argument
2933
defined_path_parts = spec.path_params.inject({}) do |params, part|
@@ -35,13 +39,11 @@
3539
params.merge(part.to_sym => 'testing')
3640
end
3741

42+
required_params.merge!(body: {}) if ['inference.put', 'inference.update', 'inference.chat_completion_unified'].include? spec.endpoint_name
43+
3844
let(:client_double) do
3945
Class.new { include Elasticsearch::API }.new.tap do |client|
4046
expect(client).to receive(:perform_request) do |_, _, _, _, _, request_params|
41-
# The create method ends up becoming an 'index' request
42-
if expected_perform_request_params[:endpoint] == 'create'
43-
expected_perform_request_params[:endpoint] = 'index'
44-
end
4547
# Check that the expected hash is passed to the perform_request method
4648
expect(request_params).to eq(expected_perform_request_params)
4749
end.and_return(response_double)

0 commit comments

Comments
 (0)