spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.7.0 vs spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.8.0.pre

- old
+ new

@@ -1,13 +1,25 @@ -# Licensed to Elasticsearch B.V under one or more agreements. -# Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -# See the LICENSE file in the project root for more information +# 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 Elasticsearch::Transport::Client do - let(:client) do described_class.new.tap do |_client| allow(_client).to receive(:__build_connections) end end @@ -1128,9 +1140,35 @@ it 'uses X-Opaque-Id in the header' do allow(client).to receive(:perform_request) { OpenStruct.new(body: '') } expect { client.search(opaque_id: 'opaque_id') }.not_to raise_error expect(client).to have_received(:perform_request) .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {}) + end + end + end + + context 'when Elasticsearch response includes a warning header' do + let(:client) do + Elasticsearch::Transport::Client.new(hosts: hosts) + end + + let(:warning) { 'Elasticsearch warning: "deprecation warning"' } + + it 'prints a warning' do + allow_any_instance_of(Elasticsearch::Transport::Transport::Response).to receive(:headers) do + { 'warning' => warning } + end + + begin + stderr = $stderr + fake_stderr = StringIO.new + $stderr = fake_stderr + + client.perform_request('GET', '/') + fake_stderr.rewind + expect(fake_stderr.string).to eq("warning: #{warning}\n") + ensure + $stderr = stderr end end end context 'when a header is set on an endpoint request' do