elastic-transport 8.1.1 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +47 -7
- data/.gitignore +1 -1
- data/CHANGELOG.md +6 -5
- data/Gemfile +4 -8
- data/Gemfile-faraday1.gemfile +39 -0
- data/README.md +1 -1
- data/Rakefile +48 -1
- data/elastic-transport.gemspec +5 -8
- data/lib/elastic/transport/client.rb +12 -10
- data/lib/elastic/transport/meta_header.rb +8 -8
- data/lib/elastic/transport/transport/base.rb +53 -50
- data/lib/elastic/transport/transport/errors.rb +2 -4
- data/lib/elastic/transport/transport/http/curb.rb +28 -25
- data/lib/elastic/transport/transport/http/faraday.rb +29 -27
- data/lib/elastic/transport/transport/http/manticore.rb +1 -1
- data/lib/elastic/transport/transport/sniffer.rb +1 -3
- data/lib/elastic/transport/version.rb +1 -1
- data/spec/elastic/transport/base_spec.rb +4 -2
- data/spec/elastic/transport/client_spec.rb +13 -16
- data/spec/elastic/transport/meta_header_spec.rb +2 -2
- data/spec/elastic/transport/sniffer_spec.rb +0 -18
- data/spec/spec_helper.rb +4 -1
- data/test/integration/jruby_test.rb +1 -1
- data/test/integration/transport_test.rb +86 -40
- data/test/test_helper.rb +8 -5
- data/test/unit/adapters_test.rb +88 -0
- data/test/unit/transport_curb_test.rb +2 -3
- metadata +17 -70
@@ -18,7 +18,6 @@
|
|
18
18
|
module Elastic
|
19
19
|
module Transport
|
20
20
|
module Transport
|
21
|
-
|
22
21
|
# Generic client error
|
23
22
|
#
|
24
23
|
class Error < StandardError; end
|
@@ -78,14 +77,13 @@ module Elastic
|
|
78
77
|
505 => 'HTTPVersionNotSupported',
|
79
78
|
506 => 'VariantAlsoNegotiates',
|
80
79
|
510 => 'NotExtended'
|
81
|
-
}
|
80
|
+
}.freeze
|
82
81
|
|
83
|
-
ERRORS = HTTP_STATUSES.
|
82
|
+
ERRORS = HTTP_STATUSES.each_with_object({}) do |error, sum|
|
84
83
|
status, name = error
|
85
84
|
sum[status] = Errors.const_set name, Class.new(ServerError)
|
86
85
|
sum
|
87
86
|
end
|
88
|
-
|
89
87
|
end
|
90
88
|
end
|
91
89
|
end
|
@@ -37,31 +37,34 @@ module Elastic
|
|
37
37
|
body, headers = compress_request(body, headers)
|
38
38
|
|
39
39
|
case method
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
when 'HEAD'
|
41
|
+
connection.connection.set :nobody, true
|
42
|
+
when 'GET', 'POST', 'PUT', 'DELETE'
|
43
|
+
connection.connection.set :nobody, false
|
44
|
+
connection.connection.put_data = body if body
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
46
|
+
if headers
|
47
|
+
if connection.connection.headers
|
48
|
+
connection.connection.headers.merge!(headers)
|
49
|
+
else
|
50
|
+
connection.connection.headers = headers
|
52
51
|
end
|
52
|
+
end
|
53
53
|
|
54
|
-
|
54
|
+
else raise ArgumentError, "Unsupported HTTP method: #{method}"
|
55
55
|
end
|
56
56
|
|
57
57
|
connection.connection.http(method.to_sym)
|
58
|
+
header_string = connection.connection.header_str.to_s
|
58
59
|
|
59
|
-
response_headers =
|
60
|
-
response_headers
|
60
|
+
_response_status, *response_headers = header_string.split(/[\r\n]+/).map(&:strip)
|
61
|
+
response_headers = Hash[response_headers.flat_map { |s| s.scan(/^(\S+): (.+)/) }].transform_keys(&:downcase)
|
61
62
|
|
62
|
-
Response.new
|
63
|
-
|
64
|
-
|
63
|
+
Response.new(
|
64
|
+
connection.connection.response_code,
|
65
|
+
decompress_response(connection.connection.body_str),
|
66
|
+
response_headers
|
67
|
+
)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
@@ -73,7 +76,7 @@ module Elastic
|
|
73
76
|
client = ::Curl::Easy.new
|
74
77
|
|
75
78
|
apply_headers(client, options)
|
76
|
-
client.url
|
79
|
+
client.url = __full_url(host)
|
77
80
|
|
78
81
|
if host[:user]
|
79
82
|
client.http_auth_types = host[:auth_type] || :basic
|
@@ -105,13 +108,13 @@ module Elastic
|
|
105
108
|
|
106
109
|
def user_agent_header(client)
|
107
110
|
@user_agent ||= begin
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
|
112
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
113
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
114
|
+
end
|
115
|
+
meta << "Curb #{Curl::CURB_VERSION}"
|
116
|
+
"elastic-transport-ruby/#{VERSION} (#{meta.join('; ')})"
|
117
|
+
end
|
115
118
|
end
|
116
119
|
end
|
117
120
|
end
|
@@ -34,26 +34,27 @@ module Elastic
|
|
34
34
|
#
|
35
35
|
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
|
36
36
|
super do |connection, url|
|
37
|
-
headers =
|
38
|
-
if !headers.nil?
|
39
|
-
connection.connection.headers.merge(headers)
|
40
|
-
else
|
41
|
-
connection.connection.headers
|
42
|
-
end
|
43
|
-
else
|
44
|
-
headers
|
45
|
-
end
|
37
|
+
headers = parse_headers(headers, connection)
|
46
38
|
body = body ? __convert_to_json(body) : nil
|
47
39
|
body, headers = compress_request(body, headers)
|
48
40
|
|
49
|
-
response = connection.connection.run_request(
|
50
|
-
method.downcase.to_sym,
|
51
|
-
url,
|
52
|
-
body,
|
53
|
-
headers
|
54
|
-
)
|
41
|
+
response = connection.connection.run_request(method.downcase.to_sym, url, body, headers)
|
55
42
|
|
56
|
-
Response.new
|
43
|
+
Response.new(response.status, decompress_response(response.body), response.headers)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Merges headers already present in the connection and the ones passed in to perform_request
|
48
|
+
#
|
49
|
+
def parse_headers(headers, connection)
|
50
|
+
if connection.connection.headers
|
51
|
+
if !headers.nil?
|
52
|
+
connection.connection.headers.merge(headers)
|
53
|
+
else
|
54
|
+
connection.connection.headers
|
55
|
+
end
|
56
|
+
else
|
57
|
+
headers
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -73,10 +74,10 @@ module Elastic
|
|
73
74
|
#
|
74
75
|
def host_unreachable_exceptions
|
75
76
|
[
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
::Faraday::ConnectionFailed,
|
78
|
+
::Faraday::TimeoutError,
|
79
|
+
::Faraday.const_defined?(:ServerError) ? ::Faraday::ServerError : nil,
|
80
|
+
::Faraday::SSLError
|
80
81
|
].compact
|
81
82
|
end
|
82
83
|
|
@@ -84,13 +85,14 @@ module Elastic
|
|
84
85
|
|
85
86
|
def user_agent_header(client)
|
86
87
|
@user_agent ||= begin
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
|
89
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
90
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} " \
|
91
|
+
"#{RbConfig::CONFIG['target_cpu']}"
|
92
|
+
end
|
93
|
+
meta << client.headers[USER_AGENT_STR]
|
94
|
+
"elastic-transport-ruby/#{VERSION} (#{meta.join('; ')})"
|
95
|
+
end
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
@@ -162,7 +162,7 @@ module Elastic
|
|
162
162
|
private
|
163
163
|
|
164
164
|
def apply_headers(options)
|
165
|
-
headers = options[:headers]
|
165
|
+
headers = options[:headers] || options.dig(:transport_options, :headers) || {}
|
166
166
|
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
167
167
|
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || find_value(@request_options[:headers], USER_AGENT_REGEX) || user_agent_header
|
168
168
|
headers[ACCEPT_ENCODING] = GZIP if use_compression?
|
@@ -76,9 +76,7 @@ module Elastic
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def parse_publish_address(publish_address)
|
79
|
-
#
|
80
|
-
return parse_address_port(publish_address[6..-2]) if publish_address =~ /^inet\[.*\]$/
|
81
|
-
|
79
|
+
# publish_address is in the format hostname/ip:port
|
82
80
|
if publish_address =~ /\//
|
83
81
|
parts = publish_address.partition('/')
|
84
82
|
[ parts[0], parse_address_port(parts[2])[1] ]
|
@@ -105,7 +105,8 @@ describe Elastic::Transport::Transport::Base do
|
|
105
105
|
let(:arguments) do
|
106
106
|
{
|
107
107
|
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
108
|
-
retry_on_failure: 2
|
108
|
+
retry_on_failure: 2,
|
109
|
+
adapter: :net_http
|
109
110
|
}
|
110
111
|
end
|
111
112
|
|
@@ -129,7 +130,8 @@ describe Elastic::Transport::Transport::Base do
|
|
129
130
|
let(:arguments) do
|
130
131
|
{
|
131
132
|
hosts: ELASTICSEARCH_HOSTS,
|
132
|
-
retry_on_status: ['404']
|
133
|
+
retry_on_status: ['404'],
|
134
|
+
adapter: :net_http
|
133
135
|
}
|
134
136
|
end
|
135
137
|
|
@@ -191,8 +191,8 @@ describe Elastic::Transport::Client do
|
|
191
191
|
it 'uses Faraday NetHttp' do
|
192
192
|
expect(adapter).to eq Faraday::Adapter::NetHttp
|
193
193
|
end
|
194
|
-
end
|
195
|
-
end
|
194
|
+
end
|
195
|
+
end unless jruby?
|
196
196
|
|
197
197
|
context 'when the adapter is patron' do
|
198
198
|
let(:adapter) do
|
@@ -204,9 +204,10 @@ describe Elastic::Transport::Client do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
it 'uses Faraday with the adapter' do
|
207
|
+
require 'faraday/patron'
|
207
208
|
expect(adapter).to eq Faraday::Adapter::Patron
|
208
209
|
end
|
209
|
-
end
|
210
|
+
end unless jruby?
|
210
211
|
|
211
212
|
context 'when the adapter is typhoeus' do
|
212
213
|
let(:adapter) do
|
@@ -214,6 +215,8 @@ describe Elastic::Transport::Client do
|
|
214
215
|
end
|
215
216
|
|
216
217
|
let(:client) do
|
218
|
+
require 'faraday/typhoeus' if is_faraday_v2?
|
219
|
+
|
217
220
|
described_class.new(adapter: :typhoeus, enable_meta_header: false)
|
218
221
|
end
|
219
222
|
|
@@ -234,7 +237,7 @@ describe Elastic::Transport::Client do
|
|
234
237
|
it 'uses Faraday with the adapter' do
|
235
238
|
expect(adapter).to eq Faraday::Adapter::Patron
|
236
239
|
end
|
237
|
-
end
|
240
|
+
end unless jruby?
|
238
241
|
|
239
242
|
context 'when the adapter can be detected', unless: jruby? do
|
240
243
|
around do |example|
|
@@ -274,7 +277,7 @@ describe Elastic::Transport::Client do
|
|
274
277
|
it 'sets the logger' do
|
275
278
|
expect(handlers).to include(Faraday::Response::Logger)
|
276
279
|
end
|
277
|
-
end
|
280
|
+
end unless jruby?
|
278
281
|
end
|
279
282
|
|
280
283
|
shared_examples_for 'a client that extracts hosts' do
|
@@ -1191,17 +1194,7 @@ describe Elastic::Transport::Client do
|
|
1191
1194
|
|
1192
1195
|
context 'when the client connects to Elasticsearch' do
|
1193
1196
|
let(:logger) do
|
1194
|
-
Logger.new(
|
1195
|
-
logger.formatter = proc do |severity, datetime, progname, msg|
|
1196
|
-
color = case severity
|
1197
|
-
when /INFO/ then :green
|
1198
|
-
when /ERROR|WARN|FATAL/ then :red
|
1199
|
-
when /DEBUG/ then :cyan
|
1200
|
-
else :white
|
1201
|
-
end
|
1202
|
-
ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
|
1203
|
-
end
|
1204
|
-
end unless ENV['QUIET']
|
1197
|
+
Logger.new($stderr) unless ENV['QUIET']
|
1205
1198
|
end
|
1206
1199
|
|
1207
1200
|
let(:port) do
|
@@ -1263,6 +1256,8 @@ describe Elastic::Transport::Client do
|
|
1263
1256
|
end
|
1264
1257
|
|
1265
1258
|
context 'when the Faraday adapter is set in the block' do
|
1259
|
+
require 'faraday/net_http_persistent' if is_faraday_v2?
|
1260
|
+
|
1266
1261
|
let(:client) do
|
1267
1262
|
Elastic::Transport::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
|
1268
1263
|
client.adapter(:net_http_persistent)
|
@@ -1414,6 +1409,8 @@ describe Elastic::Transport::Client do
|
|
1414
1409
|
end
|
1415
1410
|
|
1416
1411
|
context 'when using the HTTPClient adapter' do
|
1412
|
+
require 'faraday/httpclient'
|
1413
|
+
|
1417
1414
|
let(:client) do
|
1418
1415
|
described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)
|
1419
1416
|
end
|
@@ -155,7 +155,7 @@ describe Elastic::Transport::Client do
|
|
155
155
|
expect(headers).to include('x-elastic-client-meta' => meta)
|
156
156
|
|
157
157
|
Typhoeus = @klass if was_required
|
158
|
-
end
|
158
|
+
end
|
159
159
|
|
160
160
|
it 'sets adapter in the meta header' do
|
161
161
|
require 'typhoeus'
|
@@ -163,7 +163,7 @@ describe Elastic::Transport::Client do
|
|
163
163
|
meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
|
164
164
|
expect(headers).to include('x-elastic-client-meta' => meta)
|
165
165
|
end
|
166
|
-
end
|
166
|
+
end unless jruby?
|
167
167
|
|
168
168
|
unless jruby?
|
169
169
|
let(:adapter) { :patron }
|
@@ -257,24 +257,6 @@ describe Elastic::Transport::Transport::Sniffer do
|
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
260
|
-
context 'when the address is IPv4' do
|
261
|
-
let(:publish_address) do
|
262
|
-
'inet[/127.0.0.1:9200]'
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'parses the response' do
|
266
|
-
expect(hosts.size).to eq(1)
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'correctly parses the host' do
|
270
|
-
expect(hosts[0][:host]).to eq('127.0.0.1')
|
271
|
-
end
|
272
|
-
|
273
|
-
it 'correctly parses the port' do
|
274
|
-
expect(hosts[0][:port]).to eq('9200')
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
260
|
context 'when the transport has :randomize_hosts option' do
|
279
261
|
let(:raw_response) do
|
280
262
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
data/spec/spec_helper.rb
CHANGED
@@ -21,7 +21,6 @@ end
|
|
21
21
|
|
22
22
|
require 'elastic-transport'
|
23
23
|
require 'logger'
|
24
|
-
require 'ansi/code'
|
25
24
|
require 'hashie/mash'
|
26
25
|
if defined?(JRUBY_VERSION)
|
27
26
|
require 'elastic/transport/transport/http/manticore'
|
@@ -74,6 +73,10 @@ def default_client
|
|
74
73
|
$client ||= Elastic::Transport::Client.new(hosts: ELASTICSEARCH_HOSTS)
|
75
74
|
end
|
76
75
|
|
76
|
+
def is_faraday_v2?
|
77
|
+
Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
|
78
|
+
end
|
79
|
+
|
77
80
|
module Config
|
78
81
|
def self.included(context)
|
79
82
|
# Get the hosts to use to connect an elasticsearch client.
|
@@ -18,9 +18,8 @@
|
|
18
18
|
require 'test_helper'
|
19
19
|
|
20
20
|
class Elastic::Transport::ClientIntegrationTest < Minitest::Test
|
21
|
-
context
|
21
|
+
context 'Transport' do
|
22
22
|
setup do
|
23
|
-
begin; Object.send(:remove_const, :Patron); rescue NameError; end
|
24
23
|
uri = URI(HOST)
|
25
24
|
@host = {
|
26
25
|
host: uri.host,
|
@@ -30,69 +29,116 @@ class Elastic::Transport::ClientIntegrationTest < Minitest::Test
|
|
30
29
|
}
|
31
30
|
end
|
32
31
|
|
33
|
-
should
|
34
|
-
require 'typhoeus'
|
35
|
-
require 'typhoeus/adapters/faraday'
|
36
|
-
|
32
|
+
should 'use the default Faraday adapter' do
|
37
33
|
transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
|
38
34
|
f.response :logger
|
39
|
-
f.adapter :typhoeus
|
40
35
|
end
|
41
36
|
|
42
37
|
client = Elastic::Transport::Client.new(transport: transport)
|
38
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
|
43
39
|
client.perform_request 'GET', ''
|
44
|
-
end
|
40
|
+
end
|
45
41
|
|
46
|
-
|
47
|
-
|
42
|
+
unless jruby?
|
43
|
+
should 'allow to customize the Faraday adapter to Typhoeus' do
|
44
|
+
if is_faraday_v2?
|
45
|
+
require 'faraday/typhoeus'
|
46
|
+
else
|
47
|
+
require 'typhoeus'
|
48
|
+
end
|
49
|
+
|
50
|
+
transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
|
51
|
+
f.response :logger
|
52
|
+
f.adapter :typhoeus
|
53
|
+
end
|
54
|
+
|
55
|
+
client = Elastic::Transport::Client.new(transport: transport)
|
56
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
|
57
|
+
client.perform_request 'GET', ''
|
58
|
+
end
|
48
59
|
|
49
|
-
|
50
|
-
|
51
|
-
|
60
|
+
should 'use the Curb client' do
|
61
|
+
require 'curb'
|
62
|
+
require 'elastic/transport/transport/http/curb'
|
63
|
+
|
64
|
+
transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
|
65
|
+
curl.verbose = true
|
66
|
+
end
|
67
|
+
|
68
|
+
client = Elastic::Transport::Client.new(transport: transport)
|
69
|
+
assert_equal(client.transport.class, Elastic::Transport::Transport::HTTP::Curb)
|
70
|
+
client.perform_request 'GET', ''
|
52
71
|
end
|
53
72
|
|
54
|
-
|
55
|
-
|
56
|
-
|
73
|
+
should 'deserialize JSON responses in the Curb client' do
|
74
|
+
require 'curb'
|
75
|
+
require 'elastic/transport/transport/http/curb'
|
57
76
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
options: { transport_options: { params: { format: 'yaml' } } }
|
62
|
-
)
|
77
|
+
transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
|
78
|
+
curl.verbose = true
|
79
|
+
end
|
63
80
|
|
64
|
-
|
65
|
-
|
81
|
+
client = Elastic::Transport::Client.new(transport: transport)
|
82
|
+
response = client.perform_request 'GET', ''
|
66
83
|
|
67
|
-
|
84
|
+
assert_respond_to(response.body, :to_hash)
|
85
|
+
assert_not_nil response.body['name']
|
86
|
+
assert_equal 'application/json', response.headers['content-type']
|
87
|
+
assert_equal 'Elasticsearch', response.headers['x-elastic-product']
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'allow to customize the Faraday adapter to Patron' do
|
91
|
+
if is_faraday_v2?
|
92
|
+
require 'faraday/patron'
|
93
|
+
else
|
94
|
+
require 'patron'
|
95
|
+
end
|
96
|
+
transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
|
97
|
+
f.response :logger
|
98
|
+
f.adapter :patron
|
99
|
+
end
|
100
|
+
|
101
|
+
client = Elastic::Transport::Client.new(transport: transport)
|
102
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
|
103
|
+
client.perform_request 'GET', ''
|
104
|
+
end
|
68
105
|
end
|
69
106
|
|
70
|
-
should
|
71
|
-
require '
|
72
|
-
require 'elastic/transport/transport/http/curb'
|
107
|
+
should 'allow to customize the Faraday adapter to NetHttpPersistent' do
|
108
|
+
require 'faraday/net_http_persistent'
|
73
109
|
|
74
|
-
transport = Elastic::Transport::Transport::HTTP::
|
75
|
-
|
110
|
+
transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
|
111
|
+
f.response :logger
|
112
|
+
f.adapter :net_http_persistent
|
76
113
|
end
|
77
114
|
|
78
115
|
client = Elastic::Transport::Client.new(transport: transport)
|
116
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
|
79
117
|
client.perform_request 'GET', ''
|
80
|
-
end
|
118
|
+
end
|
81
119
|
|
82
|
-
should
|
83
|
-
require '
|
84
|
-
require 'elastic/transport/transport/http/curb'
|
120
|
+
should 'allow to customize the Faraday adapter to HTTPClient' do
|
121
|
+
require 'faraday/httpclient'
|
85
122
|
|
86
|
-
transport = Elastic::Transport::Transport::HTTP::
|
87
|
-
|
123
|
+
transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
|
124
|
+
f.response :logger
|
125
|
+
f.adapter :httpclient
|
88
126
|
end
|
89
127
|
|
90
128
|
client = Elastic::Transport::Client.new(transport: transport)
|
91
|
-
|
129
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
|
130
|
+
client.perform_request 'GET', ''
|
131
|
+
end
|
92
132
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
133
|
+
should 'allow to define connection parameters and pass them' do
|
134
|
+
transport = Elastic::Transport::Transport::HTTP::Faraday.new(
|
135
|
+
hosts: [@host],
|
136
|
+
options: { transport_options: { params: { format: 'yaml' } } }
|
137
|
+
)
|
138
|
+
|
139
|
+
client = Elastic::Transport::Client.new transport: transport
|
140
|
+
response = client.perform_request 'GET', ''
|
141
|
+
assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
|
142
|
+
end
|
97
143
|
end
|
98
144
|
end
|
data/test/test_helper.rb
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
# KIND, either express or implied. See the License for the
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
|
+
require 'uri'
|
17
18
|
|
18
19
|
password = ENV['ELASTIC_PASSWORD'] || 'changeme'
|
19
20
|
host = ENV['TEST_ES_SERVER'] || 'http://localhost:9200'
|
@@ -31,15 +32,13 @@ end
|
|
31
32
|
|
32
33
|
require 'minitest/autorun'
|
33
34
|
require 'minitest/reporters'
|
34
|
-
require 'shoulda/context'
|
35
35
|
require 'mocha/minitest'
|
36
|
-
require '
|
36
|
+
require 'shoulda/context'
|
37
37
|
|
38
|
-
require 'require-prof' if ENV["REQUIRE_PROF"]
|
39
38
|
require 'elastic-transport'
|
40
|
-
require 'logger'
|
41
|
-
|
42
39
|
require 'hashie'
|
40
|
+
require 'logger'
|
41
|
+
require 'require-prof' if ENV["REQUIRE_PROF"]
|
43
42
|
|
44
43
|
RequireProf.print_timing_infos if ENV["REQUIRE_PROF"]
|
45
44
|
|
@@ -80,4 +79,8 @@ module Minitest
|
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
82
|
+
def is_faraday_v2?
|
83
|
+
Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
|
84
|
+
end
|
85
|
+
|
83
86
|
Minitest::Reporters.use! FixedMinitestSpecReporter.new
|