elasticsearch 7.13.3 → 8.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+
20
+ ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
21
+ raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
22
+
23
+ def client
24
+ @client ||= Elasticsearch::Client.new(
25
+ host: ELASTICSEARCH_URL,
26
+ user: 'elastic',
27
+ password: 'changeme'
28
+ )
29
+ end
@@ -0,0 +1,81 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ require_relative 'helpers_spec_helper'
18
+ require 'elasticsearch/helpers/scroll_helper'
19
+
20
+ context 'Elasticsearch client helpers' do
21
+ let(:index) { 'books' }
22
+ let(:body) { { size: 12, query: { match_all: {} } } }
23
+ let(:scroll_helper) { Elasticsearch::Helpers::ScrollHelper.new(client, index, body) }
24
+
25
+ before do
26
+ documents = [
27
+ { index: { _index: index, data: {name: "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561} } },
28
+ { index: { _index: index, data: {name: "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482} } },
29
+ { index: { _index: index, data: {name: "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604} } },
30
+ { index: { _index: index, data: {name: "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331} } },
31
+ { index: { _index: index, data: {name: "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408} } },
32
+ { index: { _index: index, data: {name: "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454} } },
33
+ { index: { _index: index, data: {name: "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471} } },
34
+ { index: { _index: index, data: {name: "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768} } },
35
+ { index: { _index: index, data: {name: "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585} } },
36
+ { index: { _index: index, data: {name: "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613} } },
37
+ { index: { _index: index, data: {name: "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324} } },
38
+ { index: { _index: index, data: {name: "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328} } },
39
+ { index: { _index: index, data: {name: "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227} } },
40
+ { index: { _index: index, data: {name: "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268} } },
41
+ { index: { _index: index, data: {name: "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224} } },
42
+ { index: { _index: index, data: {name: "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208} } },
43
+ { index: { _index: index, data: {name: "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275} } },
44
+ { index: { _index: index, data: {name: "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180} } },
45
+ { index: { _index: index, data: {name: "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470} } },
46
+ { index: { _index: index, data: {name: "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271} } },
47
+ { index: { _index: index, data: {name: "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311} } },
48
+ { index: { _index: index, data: {name: "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335} } },
49
+ { index: { _index: index, data: {name: "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304} } },
50
+ { index: { _index: index, data: {name: "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288 } } }
51
+ ]
52
+ client.bulk(body: documents, refresh: 'wait_for')
53
+ end
54
+
55
+ after do
56
+ client.indices.delete(index: index)
57
+ end
58
+
59
+ it 'instantiates a scroll helper' do
60
+ expect(scroll_helper).to be_an_instance_of Elasticsearch::Helpers::ScrollHelper
61
+ end
62
+
63
+ it 'searches an index' do
64
+ my_documents = []
65
+ while !(documents = scroll_helper.results).empty?
66
+ my_documents << documents
67
+ end
68
+
69
+ expect(my_documents.flatten.size).to eq 24
70
+ end
71
+
72
+ it 'uses enumerable' do
73
+ count = 0
74
+ scroll_helper.each { |a| count += 1 }
75
+ expect(count).to eq 24
76
+ expect(scroll_helper).to respond_to(:count)
77
+ expect(scroll_helper).to respond_to(:reject)
78
+ expect(scroll_helper).to respond_to(:uniq)
79
+ expect(scroll_helper.map { |a| a['_id'] }.uniq.count).to eq 24
80
+ end
81
+ end
@@ -0,0 +1,55 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ if ENV['TEST_WITH_OTEL'] == 'true'
19
+ ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
20
+ raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
21
+
22
+ require 'spec_helper'
23
+
24
+ context 'OpenTelemetry' do
25
+ let(:exporter) { EXPORTER }
26
+ before { exporter.reset }
27
+ after { exporter.reset }
28
+ let(:span) { exporter.finished_spans[0] }
29
+
30
+ let(:client) do
31
+ Elasticsearch::Client.new(
32
+ host: ELASTICSEARCH_URL,
33
+ user: 'elastic',
34
+ password: 'changeme'
35
+ )
36
+ end
37
+
38
+ after do
39
+ client.delete(index: 'myindex', id: 1); rescue
40
+ end
41
+
42
+ context 'when a request is instrumented' do
43
+ it 'sets the span name to the endpoint id' do
44
+ client.search(body: { query: { match: {a: 1} } })
45
+ expect(span.name).to eq 'search'
46
+ end
47
+
48
+ it 'sets the path parts' do
49
+ client.index(index: 'myindex', id: 1, body: { title: 'Test' })
50
+ expect(span.attributes['db.elasticsearch.path_parts.index']).to eq 'myindex'
51
+ expect(span.attributes['db.elasticsearch.path_parts.id']).to eq 1
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'elasticsearch'
19
+ require 'rspec'
20
+
21
+ RSpec.configure do |config|
22
+ config.formatter = :documentation
23
+ end
24
+
25
+ def meta_version
26
+ client.send(:client_meta_version, Elasticsearch::VERSION)
27
+ end
28
+
29
+ def jruby?
30
+ defined?(JRUBY_VERSION)
31
+ end
32
+
33
+ if ENV['TEST_WITH_OTEL'] == 'true'
34
+ require 'opentelemetry-sdk'
35
+ EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
36
+ span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER)
37
+
38
+ OpenTelemetry::SDK.configure do |c|
39
+ c.error_handler = ->(exception:, message:) { raise(exception || message) }
40
+ c.logger = Logger.new($stderr, level: ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym)
41
+ c.add_span_processor span_processor
42
+ end
43
+ end
@@ -0,0 +1,138 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+ require 'base64'
20
+
21
+ describe Elasticsearch::Client do
22
+ context 'when using API Key' do
23
+ let(:authorization_header) do
24
+ client.transport.connections.first.connection.headers['Authorization']
25
+ end
26
+
27
+ context 'when an encoded api_key is provided' do
28
+ let(:client) do
29
+ described_class.new(api_key: 'an_api_key')
30
+ end
31
+
32
+ it 'Adds the ApiKey header to the connection' do
33
+ expect(authorization_header).to eq('ApiKey an_api_key')
34
+ end
35
+ end
36
+
37
+ context 'when an un-encoded api_key is provided' do
38
+ let(:client) do
39
+ described_class.new(api_key: { id: 'my_id', api_key: 'my_api_key' })
40
+ end
41
+
42
+ it 'Adds the ApiKey header to the connection' do
43
+ expect(authorization_header).to eq("ApiKey #{Base64.strict_encode64('my_id:my_api_key')}")
44
+ end
45
+ end
46
+
47
+ context 'when basic auth and api_key are provided' do
48
+ let(:client) do
49
+ described_class.new(
50
+ api_key: { id: 'my_id', api_key: 'my_api_key' },
51
+ host: 'http://elastic:password@localhost:9200'
52
+ )
53
+ end
54
+
55
+ it 'removes basic auth credentials' do
56
+ expect(authorization_header).not_to match(/^Basic/)
57
+ expect(authorization_header).to match(/^ApiKey/)
58
+ end
59
+ end
60
+
61
+ context 'when other headers were specified' do
62
+ let(:client) do
63
+ described_class.new(
64
+ api_key: 'elasticsearch_api_key',
65
+ transport_options: { headers: { 'x-test-header' => 'test' } }
66
+ )
67
+ end
68
+
69
+ it 'Adds the ApiKey header to the connection and keeps the header' do
70
+ header = client.transport.connections.first.connection.headers
71
+ expect(header['Authorization']).to eq('ApiKey elasticsearch_api_key')
72
+ expect(header['X-Test-Header']).to eq('test')
73
+ end
74
+ end
75
+
76
+ context 'when sending transport_options but no headers were specified' do
77
+ let(:client) do
78
+ described_class.new(
79
+ api_key: 'elasticsearch_api_key',
80
+ transport_options: { ssl: { verify: false } }
81
+ )
82
+ end
83
+
84
+ it 'Adds the ApiKey header to the connection and keeps the options' do
85
+ header = client.transport.connections.first.connection.headers
86
+ expect(header['Authorization']).to eq('ApiKey elasticsearch_api_key')
87
+ expect(client.transport.options[:transport_options]).to include({ ssl: { verify: false } })
88
+ expect(client.transport.options[:transport_options][:headers]).to include('Authorization' => 'ApiKey elasticsearch_api_key')
89
+ end
90
+ end
91
+
92
+ context 'when other headers and options were specified' do
93
+ let(:client) do
94
+ described_class.new(
95
+ api_key: 'elasticsearch_api_key',
96
+ transport_options: {
97
+ headers: { 'x-test-header' => 'test' },
98
+ ssl: { verify: false }
99
+ }
100
+ )
101
+ end
102
+
103
+ it 'Adds the ApiKey header to the connection and keeps the header' do
104
+ header = client.transport.connections.first.connection.headers
105
+ expect(header['X-Test-Header']).to eq('test')
106
+ expect(header['Authorization']).to eq('ApiKey elasticsearch_api_key')
107
+ expect(client.transport.options[:transport_options]).to include({ ssl: { verify: false } })
108
+ expect(client.transport.options[:transport_options][:headers]).to include('Authorization' => 'ApiKey elasticsearch_api_key')
109
+ end
110
+ end
111
+
112
+ context 'Metaheader' do
113
+ let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
114
+ let(:meta_header) do
115
+ if jruby?
116
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
117
+ else
118
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
119
+ end
120
+ end
121
+
122
+ context 'when using API Key' do
123
+ let(:client) do
124
+ described_class.new(api_key: 'an_api_key')
125
+ end
126
+
127
+ let(:headers) do
128
+ client.transport.connections.first.connection.headers
129
+ end
130
+
131
+ it 'adds the ApiKey header to the connection' do
132
+ expect(authorization_header).to eq('ApiKey an_api_key')
133
+ expect(headers).to include('x-elastic-client-meta' => meta_header)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,167 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+
20
+ describe Elasticsearch::Client do
21
+ context 'when cloud credentials are provided' do
22
+ let(:client) do
23
+ described_class.new(
24
+ cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
25
+ user: 'elastic',
26
+ password: 'changeme'
27
+ )
28
+ end
29
+
30
+ let(:hosts) do
31
+ client.transport.hosts
32
+ end
33
+
34
+ it 'extracts the cloud credentials' do
35
+ expect(hosts[0][:host]).to eq('abcd.localhost')
36
+ expect(hosts[0][:protocol]).to eq('https')
37
+ expect(hosts[0][:user]).to eq('elastic')
38
+ expect(hosts[0][:password]).to eq('changeme')
39
+ expect(hosts[0][:port]).to eq(443)
40
+ end
41
+
42
+ it 'creates the correct full url' do
43
+ expect(
44
+ client.transport.__full_url(client.transport.hosts[0])
45
+ ).to eq('https://elastic:changeme@abcd.localhost:443')
46
+ end
47
+
48
+ context 'when a port is specified' do
49
+ let(:client) do
50
+ described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9250)
51
+ end
52
+
53
+ it 'sets the specified port along with the cloud credentials' do
54
+ expect(hosts[0][:host]).to eq('abcd.localhost')
55
+ expect(hosts[0][:protocol]).to eq('https')
56
+ expect(hosts[0][:user]).to eq('elastic')
57
+ expect(hosts[0][:password]).to eq('changeme')
58
+ expect(hosts[0][:port]).to eq(9250)
59
+ end
60
+
61
+ it 'creates the correct full url' do
62
+ expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9250')
63
+ end
64
+ end
65
+
66
+ context 'when the cluster has alternate names' do
67
+ let(:client) do
68
+ described_class.new(
69
+ cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==',
70
+ user: 'elasticfantastic',
71
+ password: 'tobechanged'
72
+ )
73
+ end
74
+
75
+ let(:hosts) do
76
+ client.transport.hosts
77
+ end
78
+
79
+ it 'extracts the cloud credentials' do
80
+ expect(hosts[0][:host]).to eq('abcd.localhost')
81
+ expect(hosts[0][:protocol]).to eq('https')
82
+ expect(hosts[0][:user]).to eq('elasticfantastic')
83
+ expect(hosts[0][:password]).to eq('tobechanged')
84
+ expect(hosts[0][:port]).to eq(443)
85
+ end
86
+
87
+ it 'creates the correct full url' do
88
+ expect(
89
+ client.transport.__full_url(client.transport.hosts[0])
90
+ ).to eq('https://elasticfantastic:tobechanged@abcd.localhost:443')
91
+ end
92
+ end
93
+
94
+ context 'when decoded cloud id has a trailing dollar sign' do
95
+ let(:client) do
96
+ described_class.new(
97
+ cloud_id: 'a_cluster:bG9jYWxob3N0JGFiY2Qk',
98
+ user: 'elasticfantastic',
99
+ password: 'changeme'
100
+ )
101
+ end
102
+
103
+ let(:hosts) do
104
+ client.transport.hosts
105
+ end
106
+
107
+ it 'extracts the cloud credentials' do
108
+ expect(hosts[0][:host]).to eq('abcd.localhost')
109
+ expect(hosts[0][:protocol]).to eq('https')
110
+ expect(hosts[0][:user]).to eq('elasticfantastic')
111
+ expect(hosts[0][:password]).to eq('changeme')
112
+ expect(hosts[0][:port]).to eq(443)
113
+ end
114
+
115
+ it 'creates the correct full url' do
116
+ expect(
117
+ client.transport.__full_url(client.transport.hosts[0])
118
+ ).to eq('https://elasticfantastic:changeme@abcd.localhost:443')
119
+ end
120
+ end
121
+
122
+ context 'when the cloud host provides a port' do
123
+ let(:client) do
124
+ described_class.new(
125
+ cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
126
+ user: 'elastic',
127
+ password: 'changeme'
128
+ )
129
+ end
130
+
131
+ let(:hosts) do
132
+ client.transport.hosts
133
+ end
134
+
135
+ it 'creates the correct full url' do
136
+ expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
137
+ expect(hosts[0][:protocol]).to eq('https')
138
+ expect(hosts[0][:user]).to eq('elastic')
139
+ expect(hosts[0][:password]).to eq('changeme')
140
+ expect(hosts[0][:port]).to eq(9243)
141
+ end
142
+ end
143
+
144
+ context 'when the cloud host provides a port and the port is also specified' do
145
+ let(:client) do
146
+ described_class.new(
147
+ cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
148
+ user: 'elastic',
149
+ password: 'changeme',
150
+ port: 9200
151
+ )
152
+ end
153
+
154
+ let(:hosts) do
155
+ client.transport.hosts
156
+ end
157
+
158
+ it 'creates the correct full url' do
159
+ expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
160
+ expect(hosts[0][:protocol]).to eq('https')
161
+ expect(hosts[0][:user]).to eq('elastic')
162
+ expect(hosts[0][:password]).to eq('changeme')
163
+ expect(hosts[0][:port]).to eq(9243)
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,43 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ require 'spec_helper'
18
+
19
+ describe Elasticsearch::Client do
20
+ context 'when using custom transport implementation' do
21
+ class MyTransport
22
+ include Elastic::Transport::Transport::Base
23
+ def initialize(args); end
24
+ end
25
+ let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
26
+ let(:arguments) { client.instance_variable_get('@transport').instance_variable_get('@arguments') }
27
+ let(:subject) do
28
+ arguments[:transport_options][:headers]
29
+ end
30
+
31
+ let(:meta_header) do
32
+ if jruby?
33
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
34
+ else
35
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION}"
36
+ end
37
+ end
38
+
39
+ it 'doesnae set any info about the implementation in the metaheader' do
40
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
41
+ end
42
+ end
43
+ end