diff --git a/elasticsearch-api/README.md b/elasticsearch-api/README.md index 30d4489ed6..7c175ebcac 100644 --- a/elasticsearch-api/README.md +++ b/elasticsearch-api/README.md @@ -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 @@ -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. diff --git a/elasticsearch-api/Rakefile b/elasticsearch-api/Rakefile index 1583729010..6c6fa4fcf7 100644 --- a/elasticsearch-api/Rakefile +++ b/elasticsearch-api/Rakefile @@ -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' @@ -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. diff --git a/elasticsearch-api/spec/integration/api_key_spec.rb b/elasticsearch-api/spec/integration/api_key_spec.rb index 55c9d977af..f2453dc76a 100644 --- a/elasticsearch-api/spec/integration/api_key_spec.rb +++ b/elasticsearch-api/spec/integration/api_key_spec.rb @@ -18,7 +18,7 @@ # under the License. require 'base64' -require_relative './spec_helper' +require_relative './integration_helper' describe 'API keys' do before do diff --git a/elasticsearch-api/spec/integration/health_spec.rb b/elasticsearch-api/spec/integration/health_spec.rb index 8abad8dcc7..3f7207094d 100644 --- a/elasticsearch-api/spec/integration/health_spec.rb +++ b/elasticsearch-api/spec/integration/health_spec.rb @@ -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 diff --git a/elasticsearch-api/spec/integration/spec_helper.rb b/elasticsearch-api/spec/integration/integration_helper.rb similarity index 100% rename from elasticsearch-api/spec/integration/spec_helper.rb rename to elasticsearch-api/spec/integration/integration_helper.rb diff --git a/elasticsearch-api/spec/spec_helper.rb b/elasticsearch-api/spec/spec_helper.rb index b7c649670b..420a4aecd3 100644 --- a/elasticsearch-api/spec/spec_helper.rb +++ b/elasticsearch-api/spec/spec_helper.rb @@ -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) diff --git a/elasticsearch-api/spec/unit/actions/hashie_spec.rb b/elasticsearch-api/spec/unit/actions/hashie_spec.rb index 6081a21dd9..afba03698f 100644 --- a/elasticsearch-api/spec/unit/actions/hashie_spec.rb +++ b/elasticsearch-api/spec/unit/actions/hashie_spec.rb @@ -17,9 +17,10 @@ require 'spec_helper' require 'hashie' +require 'hashie/logger' +Hashie.logger = Logger.new(nil) describe 'Hashie' do - let(:json) do <<-JSON { @@ -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 diff --git a/elasticsearch-api/spec/unit/actions/nodes/info_spec.rb b/elasticsearch-api/spec/unit/actions/nodes/info_spec.rb index ad677be08d..8f69b9f5ca 100644 --- a/elasticsearch-api/spec/unit/actions/nodes/info_spec.rb +++ b/elasticsearch-api/spec/unit/actions/nodes/info_spec.rb @@ -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 @@ -43,7 +42,6 @@ end context 'when the node id is specified' do - let(:url) do '_nodes/foo' end @@ -65,7 +63,6 @@ end context 'when multiple node ids are specified as a list' do - let(:url) do '_nodes/A,B,C' end @@ -87,7 +84,6 @@ end context 'when multiple node ids are specified as a String' do - let(:url) do '_nodes/A,B,C' end @@ -109,7 +105,6 @@ end context 'when URL params are specified' do - let(:url) do '_nodes' end @@ -124,7 +119,6 @@ end context 'when metrics are specified' do - let(:url) do '_nodes/http,network' end diff --git a/elasticsearch-api/spec/unit/actions/nodes/usage_spec.rb b/elasticsearch-api/spec/unit/actions/nodes/usage_spec.rb new file mode 100644 index 0000000000..25824cd7c5 --- /dev/null +++ b/elasticsearch-api/spec/unit/actions/nodes/usage_spec.rb @@ -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 diff --git a/elasticsearch-api/spec/unit/actions/termvectors_spec.rb b/elasticsearch-api/spec/unit/actions/termvectors_spec.rb index 86e2ad33ba..d7d607832f 100644 --- a/elasticsearch-api/spec/unit/actions/termvectors_spec.rb +++ b/elasticsearch-api/spec/unit/actions/termvectors_spec.rb @@ -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 diff --git a/elasticsearch-api/spec/unit/api_response_spec.rb b/elasticsearch-api/spec/unit/api_response_spec.rb index c976602bb8..06fdb602ad 100644 --- a/elasticsearch-api/spec/unit/api_response_spec.rb +++ b/elasticsearch-api/spec/unit/api_response_spec.rb @@ -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