Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors transport_klass #422

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Compatibility with Elasticsearch
on: [push, pull_request]
on: [push]

jobs:
elasticsearch:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rubocop
on: [push, pull_request]
on: [push]

jobs:
rubocop:
Expand All @@ -11,5 +11,6 @@ jobs:
ruby-version: 2.7
- name: Run Rubocop
run: |
sudo apt-get install libcurl4-openssl-dev
bundle install
bundle exec rubocop
3 changes: 2 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 7.x
on: [push, pull_request]
on: [push]

jobs:
test-ruby:
Expand All @@ -18,6 +18,7 @@ jobs:
- name: Build and test with Rake
run: |
ruby -v
sudo apt-get install libcurl4-openssl-dev
bundle install
bundle exec rake spec:client
test-jruby:
Expand Down
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in elastic-enterprise-search.gemspec
gemspec

gem 'awesome_print'
gem 'byebug' unless defined?(JRUBY_VERSION)
gem 'faraday-patron'
gem 'rake'
gem 'rspec', '~> 3.9.0'
gem 'rspec_junit_formatter'
gem 'rubocop', '~> 1.0'
gem 'simplecov', require: false, group: :test
gem 'vcr'
gem 'webmock'
9 changes: 0 additions & 9 deletions elastic-enterprise-search.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'elastic/enterprise-search/version'

# rubocop:disable Metrics/BlockLength
Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.5'
s.name = 'elastic-enterprise-search'
Expand Down Expand Up @@ -49,12 +48,4 @@ Gem::Specification.new do |s|

s.add_dependency 'elasticsearch-transport', '>= 7.11'
s.add_runtime_dependency 'jwt', '>= 1.5', '< 3.0'
s.add_development_dependency 'awesome_print'
s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION)
s.add_development_dependency 'rspec', '~> 3.9.0'
s.add_development_dependency 'rspec_junit_formatter'
s.add_development_dependency 'rubocop', '~> 1.0'
s.add_development_dependency 'vcr'
s.add_development_dependency 'webmock'
end
# rubocop:enable Metrics/BlockLength
9 changes: 5 additions & 4 deletions lib/elastic/enterprise-search/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ def host
private

def transport_klass
case Elasticsearch::Transport::VERSION
when /7\.1[123]/
Elasticsearch::Client
else
if defined?(Elasticsearch::Transport::Client)
Elasticsearch::Transport::Client
elsif defined?(Elastic::Transport::Client)
Elastic::Transport::Client
elsif defined?(Elasticsearch::Client)
Elasticsearch::Client
end
end
end
Expand Down
24 changes: 4 additions & 20 deletions spec/app-search/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:api_key) { 'api_key' }

context 'dependant on EnterpriseSearch' do
let(:ent_client) { Elastic::EnterpriseSearch::Client.new(host: host) }
let(:ent_client) { Elastic::EnterpriseSearch::Client.new(host: host, adapter: :net_http) }
let(:app_client) { ent_client.app_search }

it 'initializes an app search client' do
Expand All @@ -34,7 +34,7 @@
end

it 'sets up authentication during initialization' do
ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
# ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
app_client = ent_client.app_search(http_auth: api_key)
expect(app_client.http_auth).to eq api_key
end
Expand All @@ -46,7 +46,7 @@
end

context 'independent from EnterpriseSearch client' do
let(:app_client) { Elastic::EnterpriseSearch::AppSearch::Client.new(host: host) }
let(:app_client) { Elastic::EnterpriseSearch::AppSearch::Client.new(host: host, adapter: :net_http) }

it 'initializes a workplace search client' do
expect(app_client).not_to be nil
Expand All @@ -55,7 +55,7 @@
end

it 'sets up authentication during initialization' do
ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
ent_client = Elastic::EnterpriseSearch::Client.new(host: host, adapter: :net_http)
app_client = ent_client.app_search(http_auth: api_key)
expect(app_client.http_auth).to eq api_key
end
Expand Down Expand Up @@ -90,28 +90,12 @@
let(:client) { described_class.new }
let(:adapter) { client.transport.transport.connections.all.first.connection.builder.adapter }

context 'when no adapter is specified' do
it 'uses Faraday NetHttp' do
expect(adapter).to eq Faraday::Adapter::NetHttp
end
end

context 'when the adapter is patron' do
let(:client) { described_class.new(adapter: :patron) }

it 'uses Faraday with the adapter' do
expect(adapter).to eq Faraday::Adapter::Patron
end
end

unless defined?(JRUBY_VERSION)
context 'when the adapter is typhoeus' do
let(:client) { described_class.new(adapter: :patron) }

it 'uses Faraday with the adapter' do
expect(adapter).to eq Faraday::Adapter::Patron
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/app-search/date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
describe Elastic::EnterpriseSearch::AppSearch::Client do
let(:host) { 'https://localhost:8080' }
let(:api_key) { 'api_key' }
let(:client) { Elastic::EnterpriseSearch::AppSearch::Client.new(host: host) }
let(:client) { Elastic::EnterpriseSearch::AppSearch::Client.new(host: host, adapter: :net_http) }
let(:subject) { client.date_to_rfc3339(date) }

context 'Date (year=2020, month=1, day=2)' do
Expand Down
17 changes: 1 addition & 16 deletions spec/enterprise-search/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'faraday/patron'

describe Elastic::EnterpriseSearch::Client do
let(:host) { 'https://localhost:8080' }
Expand Down Expand Up @@ -108,28 +109,12 @@ def messages; @strio.string; end
let(:client) { described_class.new }
let(:adapter) { client.transport.transport.connections.all.first.connection.builder.adapter }

context 'when no adapter is specified' do
it 'uses Faraday NetHttp' do
expect(adapter).to eq Faraday::Adapter::NetHttp
end
end

context 'when the adapter is patron' do
let(:client) { described_class.new(adapter: :patron) }

it 'uses Faraday with the adapter' do
expect(adapter).to eq Faraday::Adapter::Patron
end
end

unless defined?(JRUBY_VERSION)
context 'when the adapter is typhoeus' do
let(:client) { described_class.new(adapter: :patron) }

it 'uses Faraday with the adapter' do
expect(adapter).to eq Faraday::Adapter::Patron
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/enterprise-search/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
require_relative './../webmock_requires'

describe Elastic::EnterpriseSearch::Client do
let(:client) { Elastic::EnterpriseSearch::Client.new(http_auth: http_auth) }
let(:client) { Elastic::EnterpriseSearch::Client.new(http_auth: http_auth, adapter: :net_http) }
let(:stub_response) { OpenStruct.new(status: 200) }
let(:host) { 'http://localhost:3002' }
let(:http_auth) { { user: 'elastic', password: 'password' } }
Expand Down
1 change: 1 addition & 0 deletions spec/integration/app-search/app_search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'faraday/patron'
require 'logger'

# App Search Integration tests Client Configuration
Expand Down
1 change: 1 addition & 0 deletions spec/integration/enterprise_search_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'faraday/patron'

describe Elastic::EnterpriseSearch::Client do
let(:host) { ENV['ELASTIC_ENTERPRISE_HOST'] || 'http://localhost:3002' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'faraday/patron'

# Workplace Search Integration tests Client Configuration
def client
Expand Down
16 changes: 0 additions & 16 deletions spec/workplace-search/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,12 @@
let(:client) { described_class.new }
let(:adapter) { client.transport.transport.connections.all.first.connection.builder.adapter }

context 'when no adapter is specified' do
it 'uses Faraday NetHttp' do
expect(adapter).to eq Faraday::Adapter::NetHttp
end
end

context 'when the adapter is patron' do
let(:client) { described_class.new(adapter: :patron) }

it 'uses Faraday with the adapter' do
expect(adapter).to eq Faraday::Adapter::Patron
end
end

unless defined?(JRUBY_VERSION)
context 'when the adapter is typhoeus' do
let(:client) { described_class.new(adapter: :patron) }

it 'uses Faraday with the adapter' do
expect(adapter).to eq Faraday::Adapter::Patron
end
end
end
end
end
Loading