tcp-client 0.11.0 → 0.11.1

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.
@@ -1,288 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../helper'
4
-
5
- RSpec.describe TCPClient::Configuration do
6
- describe '.create' do
7
- it 'yields a configuration' do
8
- TCPClient::Configuration.create do |cfg|
9
- expect(cfg).to be_a TCPClient::Configuration
10
- end
11
- end
12
-
13
- it 'returns the configuration' do
14
- yielded_cfg = nil
15
- result = TCPClient::Configuration.create { |cfg| yielded_cfg = cfg }
16
- expect(result).to be yielded_cfg
17
- end
18
- end
19
-
20
- describe '.new' do
21
- context 'without any parameter' do
22
- subject(:configuration) { TCPClient::Configuration.new }
23
-
24
- it 'allows buffering' do
25
- expect(configuration.buffered).to be true
26
- end
27
-
28
- it 'allows keep alive signals' do
29
- expect(configuration.keep_alive).to be true
30
- end
31
-
32
- it 'allows reverse address lokup' do
33
- expect(configuration.reverse_lookup).to be true
34
- end
35
-
36
- it 'does not allow to normalize network errors' do
37
- expect(configuration.normalize_network_errors).to be false
38
- end
39
-
40
- it 'does not allow SSL connections' do
41
- expect(configuration.ssl?).to be false
42
- end
43
-
44
- it 'configures no timeout values' do
45
- expect(configuration.connect_timeout).to be_nil
46
- expect(configuration.read_timeout).to be_nil
47
- expect(configuration.write_timeout).to be_nil
48
- end
49
-
50
- it 'configures default errors' do
51
- expect(
52
- configuration.connect_timeout_error
53
- ).to be TCPClient::ConnectTimeoutError
54
- expect(
55
- configuration.read_timeout_error
56
- ).to be TCPClient::ReadTimeoutError
57
- expect(
58
- configuration.write_timeout_error
59
- ).to be TCPClient::WriteTimeoutError
60
- end
61
- end
62
-
63
- context 'when options are given' do
64
- let(:options) { double(:options) }
65
-
66
- it 'calls #configure with given options' do
67
- expect_any_instance_of(TCPClient::Configuration).to receive(
68
- :configure
69
- ).once.with(options)
70
-
71
- TCPClient::Configuration.new(options)
72
- end
73
- end
74
- end
75
-
76
- describe '#configure' do
77
- subject(:configuration) do
78
- TCPClient::Configuration.new.configure(
79
- buffered: false,
80
- keep_alive: false,
81
- reverse_lookup: false,
82
- normalize_network_errors: true,
83
- ssl: true,
84
- timeout: 60,
85
- timeout_error: custom_error
86
- )
87
- end
88
- let(:custom_error) { Class.new(StandardError) }
89
-
90
- context 'with valid options' do
91
- it 'allows to configure buffering' do
92
- expect(configuration.buffered).to be false
93
- end
94
-
95
- it 'allows to configure keep alive signals' do
96
- expect(configuration.keep_alive).to be false
97
- end
98
-
99
- it 'allows to configure reverse address lookup' do
100
- expect(configuration.reverse_lookup).to be false
101
- end
102
-
103
- it 'allows to configure to normalize network errors' do
104
- expect(configuration.normalize_network_errors).to be true
105
- end
106
-
107
- it 'allows to configures SSL connections' do
108
- expect(configuration.ssl?).to be true
109
- end
110
-
111
- it 'allows to configure no timeout values' do
112
- expect(configuration.connect_timeout).to be 60
113
- expect(configuration.read_timeout).to be 60
114
- expect(configuration.write_timeout).to be 60
115
- end
116
-
117
- it 'allows to configure timeout errors' do
118
- expect(configuration.connect_timeout_error).to be custom_error
119
- expect(configuration.read_timeout_error).to be custom_error
120
- expect(configuration.write_timeout_error).to be custom_error
121
- end
122
-
123
- it 'allows to configure dedicated timeout values' do
124
- configuration.configure(
125
- connect_timeout: 21,
126
- read_timeout: 42,
127
- write_timeout: 84
128
- )
129
- expect(configuration.connect_timeout).to be 21
130
- expect(configuration.read_timeout).to be 42
131
- expect(configuration.write_timeout).to be 84
132
- end
133
-
134
- it 'allows to configure dedicated timeout errors' do
135
- custom_connect = Class.new(StandardError)
136
- custom_read = Class.new(StandardError)
137
- custom_write = Class.new(StandardError)
138
- configuration.configure(
139
- connect_timeout_error: custom_connect,
140
- read_timeout_error: custom_read,
141
- write_timeout_error: custom_write
142
- )
143
- expect(configuration.connect_timeout_error).to be custom_connect
144
- expect(configuration.read_timeout_error).to be custom_read
145
- expect(configuration.write_timeout_error).to be custom_write
146
- end
147
- end
148
-
149
- context 'when an invalid attribute is given' do
150
- it 'raises an error' do
151
- expect { configuration.configure(invalid: :value) }.to raise_error(
152
- TCPClient::UnknownAttributeError
153
- )
154
- end
155
- end
156
-
157
- context 'when no exception class is used to configure a timeout error' do
158
- it 'raises with invalid connect_timeout_error' do
159
- expect do
160
- configuration.configure(connect_timeout_error: double(:something))
161
- end.to raise_error(TCPClient::NotAnExceptionError)
162
- end
163
-
164
- it 'raises with invalid read_timeout_error' do
165
- expect do
166
- configuration.configure(read_timeout_error: double(:something))
167
- end.to raise_error(TCPClient::NotAnExceptionError)
168
- end
169
-
170
- it 'raises with invalid write_timeout_error' do
171
- expect do
172
- configuration.configure(write_timeout_error: double(:something))
173
- end.to raise_error(TCPClient::NotAnExceptionError)
174
- end
175
- end
176
- end
177
-
178
- describe '#to_h' do
179
- subject(:configuration) do
180
- TCPClient::Configuration.new(
181
- buffered: false,
182
- connect_timeout: 1,
183
- read_timeout: 2,
184
- write_timeout: 3,
185
- ssl: {
186
- min_version: :TLS1_2,
187
- max_version: :TLS1_3
188
- }
189
- )
190
- end
191
-
192
- it 'returns itself as an Hash' do
193
- expect(configuration.to_h).to eq(
194
- buffered: false,
195
- keep_alive: true,
196
- reverse_lookup: true,
197
- connect_timeout: 1,
198
- connect_timeout_error: TCPClient::ConnectTimeoutError,
199
- read_timeout: 2,
200
- read_timeout_error: TCPClient::ReadTimeoutError,
201
- write_timeout: 3,
202
- write_timeout_error: TCPClient::WriteTimeoutError,
203
- normalize_network_errors: false,
204
- ssl_params: {
205
- min_version: :TLS1_2,
206
- max_version: :TLS1_3
207
- }
208
- )
209
- end
210
- end
211
-
212
- describe '#dup' do
213
- subject(:duplicate) { configuration.dup }
214
- let(:configuration) do
215
- TCPClient::Configuration.new(
216
- buffered: false,
217
- connect_timeout: 1,
218
- read_timeout: 2,
219
- write_timeout: 3,
220
- ssl: {
221
- min_version: :TLS1_2,
222
- max_version: :TLS1_3
223
- }
224
- )
225
- end
226
-
227
- it 'returns a new instance' do
228
- expect(duplicate).to be_a TCPClient::Configuration
229
- expect(duplicate.__id__).not_to eq configuration.__id__
230
- end
231
-
232
- it 'contains same values as the original' do
233
- expect(duplicate.buffered).to be false
234
- expect(duplicate.connect_timeout).to be 1
235
- expect(duplicate.read_timeout).to be 2
236
- expect(duplicate.write_timeout).to be 3
237
- expect(duplicate.ssl?).to be true
238
- expect(duplicate.ssl_params).to eq(
239
- min_version: :TLS1_2,
240
- max_version: :TLS1_3
241
- )
242
- end
243
- end
244
-
245
- describe 'comparison' do
246
- context 'comparing two equal instances' do
247
- let(:config_a) { TCPClient::Configuration.new(timeout: 10) }
248
- let(:config_b) { TCPClient::Configuration.new(timeout: 10) }
249
-
250
- it 'compares to equal' do
251
- expect(config_a).to eq config_b
252
- end
253
-
254
- context 'using the == operator' do
255
- it 'compares to equal' do
256
- expect(config_a == config_b).to be true
257
- end
258
- end
259
-
260
- context 'using the === operator' do
261
- it 'compares to equal' do
262
- expect(config_a === config_b).to be true
263
- end
264
- end
265
- end
266
-
267
- context 'comparing two non-equal instances' do
268
- let(:config_a) { TCPClient::Configuration.new(timeout: 10) }
269
- let(:config_b) { TCPClient::Configuration.new(timeout: 20) }
270
-
271
- it 'compares not to equal' do
272
- expect(config_a).not_to eq config_b
273
- end
274
-
275
- context 'using the == operator' do
276
- it 'compares not to equal' do
277
- expect(config_a == config_b).to be false
278
- end
279
- end
280
-
281
- context 'using the === operator' do
282
- it 'compares not to equal' do
283
- expect(config_a === config_b).to be false
284
- end
285
- end
286
- end
287
- end
288
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../helper'
4
-
5
- RSpec.describe 'TCPClient.configure' do
6
- it 'is the default configuration' do
7
- expect(TCPClient.configure).to be TCPClient::Configuration.default
8
- end
9
-
10
- context 'called with parameters' do
11
- it 'creates a new configuratiion' do
12
- options = double(:options)
13
- expect(TCPClient::Configuration).to receive(:create).once.with(options)
14
- TCPClient.configure(options)
15
- end
16
-
17
- it 'returns the new configuratiion' do
18
- expect(TCPClient::Configuration).to receive(:create).and_return(:a_result)
19
- TCPClient.configure(something: :new)
20
- expect(TCPClient::Configuration.default).to be :a_result
21
- end
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../helper'
4
-
5
- RSpec.describe 'TCPClient::VERSION' do
6
- it 'is a valid version string' do
7
- expect(TCPClient::VERSION).to match(/\d+\.\d+\.\d+/)
8
- end
9
-
10
- it 'is frozen' do
11
- expect(TCPClient::VERSION.frozen?).to be true
12
- end
13
- end