tcp-client 0.10.1 → 0.11.2

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