|
| 1 | +# Copyright 2024 DeepL SE (https://www.deepl.com) |
| 2 | +# Use of this source code is governed by an MIT |
| 3 | +# license that can be found in the LICENSE file. |
| 4 | +# frozen_string_literal: true |
| 5 | + |
| 6 | +require 'spec_helper' |
| 7 | + |
| 8 | +describe DeepL::HTTPClientOptions do |
| 9 | + describe '#initialize' do |
| 10 | + context 'when initialized without arguments' do |
| 11 | + it 'sets default values' do |
| 12 | + options = DeepL::HTTPClientOptions.new |
| 13 | + expect(options.proxy).to eq({}) |
| 14 | + expect(options.cert_path).to be_nil |
| 15 | + expect(options.enable_ssl_verification).to be true |
| 16 | + expect(options.open_timeout).to be_nil |
| 17 | + expect(options.read_timeout).to be_nil |
| 18 | + expect(options.write_timeout).to be_nil |
| 19 | + expect(options.ssl_timeout).to be_nil |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + context 'when initialized with all parameters' do |
| 24 | + it 'sets all attributes correctly' do |
| 25 | + proxy = { 'proxy_addr' => 'proxy.example.com', 'proxy_port' => 8080 } |
| 26 | + cert_path = '/path/to/cert.pem' |
| 27 | + options = DeepL::HTTPClientOptions.new( |
| 28 | + proxy, |
| 29 | + cert_path, |
| 30 | + enable_ssl_verification: false, |
| 31 | + open_timeout: 5, |
| 32 | + read_timeout: 10, |
| 33 | + write_timeout: 15, |
| 34 | + ssl_timeout: 20 |
| 35 | + ) |
| 36 | + expect(options.proxy).to eq(proxy) |
| 37 | + expect(options.proxy['proxy_addr']).to eq('proxy.example.com') |
| 38 | + expect(options.proxy['proxy_port']).to eq(8080) |
| 39 | + |
| 40 | + expect(options.cert_path).to eq(cert_path) |
| 41 | + expect(options.enable_ssl_verification).to be false |
| 42 | + expect(options.open_timeout).to eq(5) |
| 43 | + expect(options.read_timeout).to eq(10) |
| 44 | + expect(options.write_timeout).to eq(15) |
| 45 | + expect(options.ssl_timeout).to eq(20) |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + context 'when initialized with invalid keyword arguments' do |
| 50 | + it 'raises an ArgumentError' do |
| 51 | + expect { |
| 52 | + DeepL::HTTPClientOptions.new({}, nil, invalid_option: true) |
| 53 | + }.to raise_error(ArgumentError) |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context 'attribute readers' do |
| 58 | + it 'does not allow attributes to be modified after initialization' do |
| 59 | + options = DeepL::HTTPClientOptions.new |
| 60 | + expect { |
| 61 | + options.proxy = { 'proxy_addr' => 'new.proxy.com' } |
| 62 | + }.to raise_error(NoMethodError) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments