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

FIX: default with_session client options #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 lib/http_client_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HTTPClientOptions
attr_reader :proxy, :send_platform_info, :enable_ssl_verification, :cert_path, :open_timeout,
:read_timeout, :write_timeout, :ssl_timeout

def initialize(proxy, cert_path, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
def initialize(proxy = {}, cert_path = nil, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
read_timeout: nil, write_timeout: nil, ssl_timeout: nil)
@proxy = proxy
@enable_ssl_verification = enable_ssl_verification
Expand Down
66 changes: 66 additions & 0 deletions spec/http_client_options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2024 DeepL SE (https://www.deepl.com)
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
# frozen_string_literal: true

require 'spec_helper'

describe DeepL::HTTPClientOptions do
describe '#initialize' do
context 'when initialized without arguments' do
it 'sets default values' do
options = DeepL::HTTPClientOptions.new
expect(options.proxy).to eq({})
expect(options.cert_path).to be_nil
expect(options.enable_ssl_verification).to be true
expect(options.open_timeout).to be_nil
expect(options.read_timeout).to be_nil
expect(options.write_timeout).to be_nil
expect(options.ssl_timeout).to be_nil
end
end

context 'when initialized with all parameters' do
it 'sets all attributes correctly' do
proxy = { 'proxy_addr' => 'proxy.example.com', 'proxy_port' => 8080 }
cert_path = '/path/to/cert.pem'
options = DeepL::HTTPClientOptions.new(
proxy,
cert_path,
enable_ssl_verification: false,
open_timeout: 5,
read_timeout: 10,
write_timeout: 15,
ssl_timeout: 20
)
expect(options.proxy).to eq(proxy)
expect(options.proxy['proxy_addr']).to eq('proxy.example.com')
expect(options.proxy['proxy_port']).to eq(8080)

expect(options.cert_path).to eq(cert_path)
expect(options.enable_ssl_verification).to be false
expect(options.open_timeout).to eq(5)
expect(options.read_timeout).to eq(10)
expect(options.write_timeout).to eq(15)
expect(options.ssl_timeout).to eq(20)
end
end

context 'when initialized with invalid keyword arguments' do
it 'raises an ArgumentError' do
expect {
DeepL::HTTPClientOptions.new({}, nil, invalid_option: true)
}.to raise_error(ArgumentError)
end
end

context 'attribute readers' do
it 'does not allow attributes to be modified after initialization' do
options = DeepL::HTTPClientOptions.new
expect {
options.proxy = { 'proxy_addr' => 'new.proxy.com' }
}.to raise_error(NoMethodError)
end
end
end
end