|
1428 | 1428 | end
|
1429 | 1429 | end
|
1430 | 1430 |
|
| 1431 | + context 'when using the API Compatibility Header' do |
| 1432 | + it 'sets the API compatibility headers' do |
| 1433 | + ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'true' |
| 1434 | + client = described_class.new(host: hosts) |
| 1435 | + headers = client.transport.connections.first.connection.headers |
| 1436 | + |
| 1437 | + expect(headers['Content-Type']).to eq('application/vnd.elasticsearch+json; compatible-with=7') |
| 1438 | + expect(headers['Accept']).to eq('application/vnd.elasticsearch+json;compatible-with=7') |
| 1439 | + |
| 1440 | + response = client.perform_request('GET', '/') |
| 1441 | + expect(response.headers['content-type']).to eq('application/json; charset=UTF-8') |
| 1442 | + |
| 1443 | + ENV.delete('ELASTIC_CLIENT_APIVERSIONING') |
| 1444 | + end |
| 1445 | + |
| 1446 | + it 'does not use API compatibility headers' do |
| 1447 | + val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING') |
| 1448 | + client = described_class.new(host: hosts) |
| 1449 | + expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json') |
| 1450 | + ENV['ELASTIC_CLIENT_APIVERSIONING'] = val |
| 1451 | + end |
| 1452 | + |
| 1453 | + it 'does not use API compatibility headers when it is set to unsupported values' do |
| 1454 | + val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING') |
| 1455 | + |
| 1456 | + ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'test' |
| 1457 | + client = described_class.new(host: hosts) |
| 1458 | + expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json') |
| 1459 | + |
| 1460 | + ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'false' |
| 1461 | + client = described_class.new(host: hosts) |
| 1462 | + expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json') |
| 1463 | + |
| 1464 | + ENV['ELASTIC_CLIENT_APIVERSIONING'] = '3' |
| 1465 | + client = described_class.new(host: hosts) |
| 1466 | + expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json') |
| 1467 | + ENV['ELASTIC_CLIENT_APIVERSIONING'] = val |
| 1468 | + end |
| 1469 | + end |
| 1470 | + |
1431 | 1471 | context 'when Elasticsearch response includes a warning header' do
|
1432 | 1472 | let(:client) do
|
1433 | 1473 | Elasticsearch::Transport::Client.new(hosts: hosts)
|
|
0 commit comments