elastic-transport 8.1.3 → 8.2.0

Sign up to get free protection for your applications and to get access to all the features.
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.
@@ -21,7 +21,7 @@ if JRUBY
21
21
  require 'elastic/transport/transport/http/manticore'
22
22
 
23
23
  class Elastic::Transport::ClientManticoreIntegrationTest < Minitest::Test
24
- context "Transport" do
24
+ context 'Transport' do
25
25
  setup do
26
26
  uri = URI(HOST)
27
27
  @host = {
@@ -18,9 +18,8 @@
18
18
  require 'test_helper'
19
19
 
20
20
  class Elastic::Transport::ClientIntegrationTest < Minitest::Test
21
- context "Transport" do
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 "allow to customize the Faraday adapter to Typhoeus" do
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 unless jruby?
40
+ end
45
41
 
46
- should "allow to customize the Faraday adapter to NetHttpPersistent" do
47
- require 'net/http/persistent'
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
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
50
- f.response :logger
51
- f.adapter :net_http_persistent
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
- client = Elastic::Transport::Client.new(transport: transport)
55
- client.perform_request 'GET', ''
56
- end
73
+ should 'deserialize JSON responses in the Curb client' do
74
+ require 'curb'
75
+ require 'elastic/transport/transport/http/curb'
57
76
 
58
- should "allow to define connection parameters and pass them" do
59
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(
60
- hosts: [@host],
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
- client = Elastic::Transport::Client.new transport: transport
65
- response = client.perform_request 'GET', ''
81
+ client = Elastic::Transport::Client.new(transport: transport)
82
+ response = client.perform_request 'GET', ''
66
83
 
67
- assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
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 "use the Curb client" do
71
- require 'curb'
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::Curb.new(hosts: [@host]) do |curl|
75
- curl.verbose = true
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 unless JRUBY
118
+ end
81
119
 
82
- should "deserialize JSON responses in the Curb client" do
83
- require 'curb'
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::Curb.new(hosts: [@host]) do |curl|
87
- curl.verbose = true
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
- response = client.perform_request 'GET', ''
129
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
130
+ client.perform_request 'GET', ''
131
+ end
92
132
 
93
- assert_respond_to(response.body, :to_hash)
94
- assert_not_nil response.body['name']
95
- assert_equal 'application/json', response.headers['content-type']
96
- end unless jruby?
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 'ansi/code'
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
@@ -0,0 +1,88 @@
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 'test_helper'
19
+
20
+ class Elastic::Transport::ClientAdaptersUnitTest < Minitest::Test
21
+ context 'Adapters' do
22
+ setup do
23
+ begin
24
+ Object.send(:remove_const, :Patron)
25
+ rescue NameError
26
+ end
27
+ end
28
+
29
+ should 'use the default Faraday adapter' do
30
+ fork do
31
+ client = Elastic::Transport::Client.new
32
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
33
+ end
34
+ end
35
+
36
+ should 'use Patron Faraday adapter' do
37
+ fork do
38
+ if is_faraday_v2?
39
+ require 'faraday/patron'
40
+ else
41
+ require 'patron'
42
+ end
43
+
44
+ client = Elastic::Transport::Client.new
45
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
46
+ end
47
+ end
48
+
49
+ should 'use Typhoeus Faraday adapter' do
50
+ fork do
51
+ if is_faraday_v2?
52
+ require 'faraday/typhoeus'
53
+ else
54
+ require 'typhoeus'
55
+ end
56
+
57
+ client = Elastic::Transport::Client.new
58
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
59
+ end
60
+ end
61
+
62
+ should 'use NetHttpPersistent Faraday adapter' do
63
+ fork do
64
+ if is_faraday_v2?
65
+ require 'faraday/net_http_persistent'
66
+ else
67
+ require 'net/http/persistent'
68
+ end
69
+
70
+ client = Elastic::Transport::Client.new
71
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
72
+ end
73
+ end
74
+
75
+ should 'use HTTPClient Faraday adapter' do
76
+ fork do
77
+ if is_faraday_v2?
78
+ require 'faraday/httpclient'
79
+ else
80
+ require 'httpclient'
81
+ end
82
+
83
+ client = Elastic::Transport::Client.new
84
+ assert_equal(Faraday::Adapter::HTTPClient, client.transport.connections.first.connection.adapter)
85
+ end
86
+ end
87
+ end unless jruby?
88
+ end
@@ -83,11 +83,10 @@ else
83
83
  should "set application/json response header" do
84
84
  @transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
85
85
  @transport.connections.first.connection.expects(:body_str).returns('{"foo":"bar"}')
86
- @transport.connections.first.connection.expects(:header_str).returns('HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Length: 311\r\n\r\n')
86
+ @transport.connections.first.connection.expects(:header_str).returns("HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Length: 311\r\n\r\n")
87
87
 
88
88
  response = @transport.perform_request 'GET', '/'
89
-
90
- assert_equal 'application/json', response.headers['content-type']
89
+ assert_equal 'application/json; charset=UTF-8', response.headers['content-type']
91
90
  end
92
91
 
93
92
  should "handle HTTP methods" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.3
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
@@ -10,44 +10,30 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-01-24 00:00:00.000000000 Z
13
+ date: 2023-01-30 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: multi_json
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: '0'
29
15
  - !ruby/object:Gem::Dependency
30
16
  name: faraday
31
17
  requirement: !ruby/object:Gem::Requirement
32
18
  requirements:
33
- - - "~>"
19
+ - - "<"
34
20
  - !ruby/object:Gem::Version
35
- version: '1'
21
+ version: '3'
36
22
  type: :runtime
37
23
  prerelease: false
38
24
  version_requirements: !ruby/object:Gem::Requirement
39
25
  requirements:
40
- - - "~>"
26
+ - - "<"
41
27
  - !ruby/object:Gem::Version
42
- version: '1'
28
+ version: '3'
43
29
  - !ruby/object:Gem::Dependency
44
- name: bundler
30
+ name: multi_json
45
31
  requirement: !ruby/object:Gem::Requirement
46
32
  requirements:
47
33
  - - ">="
48
34
  - !ruby/object:Gem::Version
49
35
  version: '0'
50
- type: :development
36
+ type: :runtime
51
37
  prerelease: false
52
38
  version_requirements: !ruby/object:Gem::Requirement
53
39
  requirements:
@@ -55,7 +41,7 @@ dependencies:
55
41
  - !ruby/object:Gem::Version
56
42
  version: '0'
57
43
  - !ruby/object:Gem::Dependency
58
- name: cane
44
+ name: curb
59
45
  requirement: !ruby/object:Gem::Requirement
60
46
  requirements:
61
47
  - - ">="
@@ -69,7 +55,7 @@ dependencies:
69
55
  - !ruby/object:Gem::Version
70
56
  version: '0'
71
57
  - !ruby/object:Gem::Dependency
72
- name: curb
58
+ name: bundler
73
59
  requirement: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - ">="
@@ -83,7 +69,7 @@ dependencies:
83
69
  - !ruby/object:Gem::Version
84
70
  version: '0'
85
71
  - !ruby/object:Gem::Dependency
86
- name: hashie
72
+ name: cane
87
73
  requirement: !ruby/object:Gem::Requirement
88
74
  requirements:
89
75
  - - ">="
@@ -97,7 +83,7 @@ dependencies:
97
83
  - !ruby/object:Gem::Version
98
84
  version: '0'
99
85
  - !ruby/object:Gem::Dependency
100
- name: httpclient
86
+ name: hashie
101
87
  requirement: !ruby/object:Gem::Requirement
102
88
  requirements:
103
89
  - - ">="
@@ -152,34 +138,6 @@ dependencies:
152
138
  - - ">="
153
139
  - !ruby/object:Gem::Version
154
140
  version: '0'
155
- - !ruby/object:Gem::Dependency
156
- name: net-http-persistent
157
- requirement: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: '0'
162
- type: :development
163
- prerelease: false
164
- version_requirements: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- version: '0'
169
- - !ruby/object:Gem::Dependency
170
- name: patron
171
- requirement: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
176
- type: :development
177
- prerelease: false
178
- version_requirements: !ruby/object:Gem::Requirement
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- version: '0'
183
141
  - !ruby/object:Gem::Dependency
184
142
  name: pry
185
143
  requirement: !ruby/object:Gem::Requirement
@@ -278,20 +236,6 @@ dependencies:
278
236
  - - "~>"
279
237
  - !ruby/object:Gem::Version
280
238
  version: '2'
281
- - !ruby/object:Gem::Dependency
282
- name: typhoeus
283
- requirement: !ruby/object:Gem::Requirement
284
- requirements:
285
- - - "~>"
286
- - !ruby/object:Gem::Version
287
- version: '1.4'
288
- type: :development
289
- prerelease: false
290
- version_requirements: !ruby/object:Gem::Requirement
291
- requirements:
292
- - - "~>"
293
- - !ruby/object:Gem::Version
294
- version: '1.4'
295
239
  - !ruby/object:Gem::Dependency
296
240
  name: yard
297
241
  requirement: !ruby/object:Gem::Requirement
@@ -311,7 +255,7 @@ description: 'Low level Ruby client for Elastic. See the `elasticsearch` or `ela
311
255
 
312
256
  '
313
257
  email:
314
- - clients-team@elastic.co
258
+ - support@elastic.co
315
259
  executables: []
316
260
  extensions: []
317
261
  extra_rdoc_files:
@@ -325,6 +269,7 @@ files:
325
269
  - ".gitignore"
326
270
  - CHANGELOG.md
327
271
  - Gemfile
272
+ - Gemfile-faraday1.gemfile
328
273
  - LICENSE
329
274
  - README.md
330
275
  - Rakefile
@@ -361,6 +306,7 @@ files:
361
306
  - test/integration/transport_test.rb
362
307
  - test/profile/client_benchmark_test.rb
363
308
  - test/test_helper.rb
309
+ - test/unit/adapters_test.rb
364
310
  - test/unit/connection_test.rb
365
311
  - test/unit/response_test.rb
366
312
  - test/unit/serializer_test.rb
@@ -392,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
392
338
  - !ruby/object:Gem::Version
393
339
  version: '0'
394
340
  requirements: []
395
- rubygems_version: 3.5.3
341
+ rubygems_version: 3.3.7
396
342
  signing_key:
397
343
  specification_version: 4
398
344
  summary: Low level Ruby client for Elastic services.
@@ -411,6 +357,7 @@ test_files:
411
357
  - test/integration/transport_test.rb
412
358
  - test/profile/client_benchmark_test.rb
413
359
  - test/test_helper.rb
360
+ - test/unit/adapters_test.rb
414
361
  - test/unit/connection_test.rb
415
362
  - test/unit/response_test.rb
416
363
  - test/unit/serializer_test.rb