Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion elasticsearch-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Language clients are forward compatible; meaning that clients support communicat

Refer to [CONTRIBUTING](https://github.com/elastic/elasticsearch-ruby/blob/main/CONTRIBUTING.md).

The integration tests on this project run the [Elasticsearch Client tests](https://github.com/elastic/elasticsearch-clients-tests/) with the [Elasticsearch Tests Runner](https://github.com/elastic/es-test-runner-ruby/) library. This runs in CI against an Elasticsearch cluster in Docker. You can run a docker container with Elasticsearch with a Rake task from the root directory of this project:
Use `bundle exec rake test:unit` to run Unit tests. Add the environment variable `COVERAGE` to see Simplecov test coverage.

The integration tests on this project run the [Elasticsearch Client tests](https://github.com/elastic/elasticsearch-clients-tests/) with the [Elasticsearch Tests Runner](https://github.com/elastic/es-test-runner-ruby/) library. You can run a docker container with Elasticsearch with a Rake task from the root directory of this project:

```bash
$ rake es:up
Expand All @@ -27,6 +29,8 @@ This will start whatever version of Elasticsearch is set in the Buildkite pipeli
$ rake es:start[version,suite] # e.g. rake es:start[9.0.0-SNAPSHOT, free]
```

You can run the integration tests with `bundle exec rake test:integration`.

### Code generation

The code for most of this library is automatically generated. See [./utils/README.md](utils/README.md) for more information.
Expand Down
2 changes: 0 additions & 2 deletions elasticsearch-api/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace :test do
task :unit
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = 'spec/unit/**/*_spec.rb'
t.ruby_opts = '-W0'
end

desc 'Run unit and integration tests'
Expand All @@ -52,7 +51,6 @@ namespace :test do
desc 'Run Integration tests'
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = 'spec/integration/**/*_spec.rb'
t.ruby_opts = '-W0'
end

# This is the task to run the Elasticsearch REST tests which we stopped using for 9.x.
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/spec/integration/api_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# under the License.

require 'base64'
require_relative './spec_helper'
require_relative './integration_helper'

describe 'API keys' do
before do
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/spec/integration/health_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# specific language governing permissions and limitations
# under the License.

require_relative './spec_helper'
require_relative './integration_helper'

describe 'Health basic test' do
it 'performs the request' do
Expand Down
7 changes: 5 additions & 2 deletions elasticsearch-api/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
if ENV['COVERAGE'] && ENV['CI'].nil?
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start { add_filter %r{^/test|spec/} }
SimpleCov.start do
add_filter %r{^/test|spec/}
add_filter 'utils/thor'
end
end

if defined?(JRUBY_VERSION)
Expand Down
5 changes: 3 additions & 2 deletions elasticsearch-api/spec/unit/actions/hashie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

require 'spec_helper'
require 'hashie'
require 'hashie/logger'
Hashie.logger = Logger.new(nil)

describe 'Hashie' do

let(:json) do
<<-JSON
{
Expand Down Expand Up @@ -79,7 +80,7 @@
end

let(:response) do
Hashie::Mash.new MultiJson.load(json)
Hashie::Mash.new(MultiJson.load(json))
end

it 'wraps the response' do
Expand Down
18 changes: 6 additions & 12 deletions elasticsearch-api/spec/unit/actions/nodes/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
require 'spec_helper'

describe 'client.nodes#info' do

let(:expected_args) do
[
'GET',
url,
params,
nil,
{},
{ endpoint: 'nodes.info' }
'GET',
url,
params,
nil,
{},
{ endpoint: 'nodes.info' }
]
end

Expand All @@ -43,7 +42,6 @@
end

context 'when the node id is specified' do

let(:url) do
'_nodes/foo'
end
Expand All @@ -65,7 +63,6 @@
end

context 'when multiple node ids are specified as a list' do

let(:url) do
'_nodes/A,B,C'
end
Expand All @@ -87,7 +84,6 @@
end

context 'when multiple node ids are specified as a String' do

let(:url) do
'_nodes/A,B,C'
end
Expand All @@ -109,7 +105,6 @@
end

context 'when URL params are specified' do

let(:url) do
'_nodes'
end
Expand All @@ -124,7 +119,6 @@
end

context 'when metrics are specified' do

let(:url) do
'_nodes/http,network'
end
Expand Down
106 changes: 106 additions & 0 deletions elasticsearch-api/spec/unit/actions/nodes/usage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require 'spec_helper'

describe 'client.nodes#usage' do
let(:expected_args) do
[
'GET',
url,
params,
nil,
{},
{ endpoint: 'nodes.usage' }
]
end

let(:url) do
'_nodes/usage'
end

it 'performs the request' do
expect(client_double.nodes.usage).to be_a Elasticsearch::API::Response
end

let(:params) do
{}
end

context 'when the node id is specified' do
let(:url) do
'_nodes/foo/usage'
end

let(:expected_args) do
[
'GET',
url,
params,
nil,
{},
{ defined_params: { node_id: 'foo' }, endpoint: 'nodes.usage' }
]
end

it 'performs the request' do
expect(client_double.nodes.usage(node_id: 'foo')).to be_a Elasticsearch::API::Response
end
end

context 'when the metric is specified' do
let(:url) do
'_nodes/usage/metric'
end

let(:expected_args) do
[
'GET',
url,
params,
nil,
{},
{ defined_params: { metric: 'metric' }, endpoint: 'nodes.usage' }
]
end

it 'performs the request' do
expect(client_double.nodes.usage(metric: 'metric')).to be_a Elasticsearch::API::Response
end
end

context 'when both are specified' do
let(:url) do
'_nodes/foo/usage/metric'
end

let(:expected_args) do
[
'GET',
url,
params,
nil,
{},
{ defined_params: { node_id: 'foo', metric: 'metric' }, endpoint: 'nodes.usage' }
]
end

it 'performs the request' do
expect(client_double.nodes.usage(metric: 'metric', node_id: 'foo')).to be_a Elasticsearch::API::Response
end
end
end
6 changes: 5 additions & 1 deletion elasticsearch-api/spec/unit/actions/termvectors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@
end

it 'performs the request' do
expect(client_double.termvector(index: 'foo', id: '123', body: {})).to be_a Elasticsearch::API::Response
message = '[DEPRECATION] `termvector` is deprecated. Please use the plural version, `termvectors` instead.
'
expect do
client_double.termvector(index: 'foo', id: '123', body: {})
end.to output(message).to_stderr
end
end
end
4 changes: 4 additions & 0 deletions elasticsearch-api/spec/unit/api_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@
it 'returns the body which' do
expect(response.body).to eq response_body
end

it 'returns the body with to_s' do
expect(response.to_s).to eq response.body.to_s
end
end