baza.rb 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/actionlint.yml +1 -1
- data/.github/workflows/codecov.yml +1 -1
- data/.github/workflows/copyrights.yml +1 -1
- data/.github/workflows/markdown-lint.yml +1 -1
- data/.github/workflows/pdd.yml +1 -1
- data/.github/workflows/xcop.yml +1 -1
- data/.github/workflows/yamllint.yml +1 -1
- data/Gemfile +6 -6
- data/Gemfile.lock +33 -35
- data/README.md +1 -1
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +66 -21
- data/test/test_baza-rb.rb +28 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f06c63d179589bfc28c89fb3d60d4df8232fca069fdf1b225c830091765cef74
|
4
|
+
data.tar.gz: de1e9b335a7b34f702f3367980400d0667b08e78817ecef533eef0f81a38e1a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c39feaf4cd305ba697f38225203f7a6917899cdc89a0ecf0735196b9f54691ebcac0b3742659e546e083d7d7e472f54c1d7648c9722ab478968e5b8a3bfcb4
|
7
|
+
data.tar.gz: 2f37dce17730366ae52e4a4cdd1e69651038402b2a2ab9e806829c275a9140fa0164bbdc31b550a4d809235615d976bd7705ab00e5e7a9186f29898ebece114b
|
data/.github/workflows/pdd.yml
CHANGED
data/.github/workflows/xcop.yml
CHANGED
data/Gemfile
CHANGED
@@ -29,12 +29,12 @@ gem 'minitest-reporters', '1.7.1', require: false
|
|
29
29
|
gem 'net-ping', '2.0.8', require: false
|
30
30
|
gem 'rake', '13.2.1', require: false
|
31
31
|
gem 'random-port', '>0', require: false
|
32
|
-
gem 'rspec-rails', '
|
33
|
-
gem 'rubocop', '1.
|
34
|
-
gem 'rubocop-performance', '1.
|
35
|
-
gem 'rubocop-rspec', '3.0
|
32
|
+
gem 'rspec-rails', '7.0.1', require: false
|
33
|
+
gem 'rubocop', '1.66.1', require: false
|
34
|
+
gem 'rubocop-performance', '1.22.1', require: false
|
35
|
+
gem 'rubocop-rspec', '3.1.0', require: false
|
36
36
|
gem 'simplecov', '0.22.0', require: false
|
37
37
|
gem 'simplecov-cobertura', '2.1.0', require: false
|
38
38
|
gem 'wait_for', '~>0', require: false
|
39
|
-
gem 'webmock', '3.
|
40
|
-
gem 'yard', '0.9.
|
39
|
+
gem 'webmock', '3.24.0', require: false
|
40
|
+
gem 'yard', '0.9.37', require: false
|
data/Gemfile.lock
CHANGED
@@ -78,8 +78,9 @@ GEM
|
|
78
78
|
others (> 0)
|
79
79
|
tago (> 0)
|
80
80
|
yaml (~> 0.3)
|
81
|
-
faraday (2.
|
81
|
+
faraday (2.12.0)
|
82
82
|
faraday-net_http (>= 2.0, < 3.4)
|
83
|
+
json
|
83
84
|
logger
|
84
85
|
faraday-http-cache (2.5.1)
|
85
86
|
faraday (>= 0.8)
|
@@ -94,16 +95,16 @@ GEM
|
|
94
95
|
ffi (1.17.0-x86_64-darwin)
|
95
96
|
ffi (1.17.0-x86_64-linux-gnu)
|
96
97
|
hashdiff (1.1.1)
|
97
|
-
i18n (1.14.
|
98
|
+
i18n (1.14.6)
|
98
99
|
concurrent-ruby (~> 1.0)
|
99
100
|
io-console (0.7.2)
|
100
|
-
irb (1.14.
|
101
|
+
irb (1.14.1)
|
101
102
|
rdoc (>= 4.0.0)
|
102
103
|
reline (>= 0.4.2)
|
103
104
|
iri (0.8.0)
|
104
105
|
json (2.7.2)
|
105
106
|
language_server-protocol (3.17.0.3)
|
106
|
-
logger (1.6.
|
107
|
+
logger (1.6.1)
|
107
108
|
loofah (2.22.0)
|
108
109
|
crass (~> 1.0.2)
|
109
110
|
nokogiri (>= 1.12.0)
|
@@ -128,14 +129,14 @@ GEM
|
|
128
129
|
racc (~> 1.4)
|
129
130
|
others (0.0.3)
|
130
131
|
parallel (1.26.3)
|
131
|
-
parser (3.3.
|
132
|
+
parser (3.3.5.0)
|
132
133
|
ast (~> 2.4.1)
|
133
134
|
racc
|
134
135
|
psych (5.1.2)
|
135
136
|
stringio
|
136
137
|
public_suffix (6.0.1)
|
137
138
|
racc (1.8.1)
|
138
|
-
rack (3.1.
|
139
|
+
rack (3.1.8)
|
139
140
|
rack-session (2.0.0)
|
140
141
|
rack (>= 3.0.0)
|
141
142
|
rack-test (2.1.0)
|
@@ -164,45 +165,43 @@ GEM
|
|
164
165
|
rdoc (6.7.0)
|
165
166
|
psych (>= 4.0.0)
|
166
167
|
regexp_parser (2.9.2)
|
167
|
-
reline (0.5.
|
168
|
+
reline (0.5.10)
|
168
169
|
io-console (~> 0.5)
|
169
170
|
retries (0.0.5)
|
170
|
-
rexml (3.3.
|
171
|
-
|
172
|
-
rspec-core (3.13.0)
|
171
|
+
rexml (3.3.8)
|
172
|
+
rspec-core (3.13.1)
|
173
173
|
rspec-support (~> 3.13.0)
|
174
|
-
rspec-expectations (3.13.
|
174
|
+
rspec-expectations (3.13.3)
|
175
175
|
diff-lcs (>= 1.2.0, < 2.0)
|
176
176
|
rspec-support (~> 3.13.0)
|
177
|
-
rspec-mocks (3.13.
|
177
|
+
rspec-mocks (3.13.2)
|
178
178
|
diff-lcs (>= 1.2.0, < 2.0)
|
179
179
|
rspec-support (~> 3.13.0)
|
180
|
-
rspec-rails (
|
181
|
-
actionpack (>=
|
182
|
-
activesupport (>=
|
183
|
-
railties (>=
|
180
|
+
rspec-rails (7.0.1)
|
181
|
+
actionpack (>= 7.0)
|
182
|
+
activesupport (>= 7.0)
|
183
|
+
railties (>= 7.0)
|
184
184
|
rspec-core (~> 3.13)
|
185
185
|
rspec-expectations (~> 3.13)
|
186
186
|
rspec-mocks (~> 3.13)
|
187
187
|
rspec-support (~> 3.13)
|
188
188
|
rspec-support (3.13.1)
|
189
|
-
rubocop (1.
|
189
|
+
rubocop (1.66.1)
|
190
190
|
json (~> 2.3)
|
191
191
|
language_server-protocol (>= 3.17.0)
|
192
192
|
parallel (~> 1.10)
|
193
193
|
parser (>= 3.3.0.2)
|
194
194
|
rainbow (>= 2.2.2, < 4.0)
|
195
195
|
regexp_parser (>= 2.4, < 3.0)
|
196
|
-
|
197
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
196
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
198
197
|
ruby-progressbar (~> 1.7)
|
199
198
|
unicode-display_width (>= 2.4.0, < 3.0)
|
200
|
-
rubocop-ast (1.32.
|
199
|
+
rubocop-ast (1.32.3)
|
201
200
|
parser (>= 3.3.1.0)
|
202
|
-
rubocop-performance (1.
|
201
|
+
rubocop-performance (1.22.1)
|
203
202
|
rubocop (>= 1.48.1, < 2.0)
|
204
203
|
rubocop-ast (>= 1.31.1, < 2.0)
|
205
|
-
rubocop-rspec (3.0
|
204
|
+
rubocop-rspec (3.1.0)
|
206
205
|
rubocop (~> 1.61)
|
207
206
|
ruby-progressbar (1.13.0)
|
208
207
|
securerandom (0.3.1)
|
@@ -213,28 +212,27 @@ GEM
|
|
213
212
|
simplecov-cobertura (2.1.0)
|
214
213
|
rexml
|
215
214
|
simplecov (~> 0.19)
|
216
|
-
simplecov-html (0.
|
215
|
+
simplecov-html (0.13.1)
|
217
216
|
simplecov_json_formatter (0.1.4)
|
218
217
|
stringio (3.1.1)
|
219
|
-
strscan (3.1.0)
|
220
218
|
tago (0.0.2)
|
221
219
|
thor (1.3.2)
|
222
220
|
typhoeus (1.4.1)
|
223
221
|
ethon (>= 0.9.0)
|
224
222
|
tzinfo (2.0.6)
|
225
223
|
concurrent-ruby (~> 1.0)
|
226
|
-
unicode-display_width (2.
|
224
|
+
unicode-display_width (2.6.0)
|
227
225
|
uri (0.13.1)
|
228
226
|
useragent (0.16.10)
|
229
227
|
wait_for (0.1.1)
|
230
|
-
webmock (3.
|
228
|
+
webmock (3.24.0)
|
231
229
|
addressable (>= 2.8.0)
|
232
230
|
crack (>= 0.3.2)
|
233
231
|
hashdiff (>= 0.4.0, < 2.0.0)
|
234
|
-
webrick (1.8.
|
232
|
+
webrick (1.8.2)
|
235
233
|
yaml (0.3.0)
|
236
|
-
yard (0.9.
|
237
|
-
zeitwerk (2.
|
234
|
+
yard (0.9.37)
|
235
|
+
zeitwerk (2.7.0)
|
238
236
|
|
239
237
|
PLATFORMS
|
240
238
|
arm64-darwin-22
|
@@ -251,15 +249,15 @@ DEPENDENCIES
|
|
251
249
|
net-ping (= 2.0.8)
|
252
250
|
rake (= 13.2.1)
|
253
251
|
random-port (> 0)
|
254
|
-
rspec-rails (=
|
255
|
-
rubocop (= 1.
|
256
|
-
rubocop-performance (= 1.
|
257
|
-
rubocop-rspec (= 3.0
|
252
|
+
rspec-rails (= 7.0.1)
|
253
|
+
rubocop (= 1.66.1)
|
254
|
+
rubocop-performance (= 1.22.1)
|
255
|
+
rubocop-rspec (= 3.1.0)
|
258
256
|
simplecov (= 0.22.0)
|
259
257
|
simplecov-cobertura (= 2.1.0)
|
260
258
|
wait_for (~> 0)
|
261
|
-
webmock (= 3.
|
262
|
-
yard (= 0.9.
|
259
|
+
webmock (= 3.24.0)
|
260
|
+
yard (= 0.9.37)
|
263
261
|
|
264
262
|
BUNDLED WITH
|
265
263
|
2.4.22
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
[![Hits-of-Code](https://hitsofcode.com/github/zerocracy/baza.rb)](https://hitsofcode.com/view/github/zerocracy/baza.rb)
|
11
11
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/zerocracy/baza.rb/blob/master/LICENSE.txt)
|
12
12
|
|
13
|
-
It's an
|
13
|
+
It's an client for [Zerocracy API](https://www.zerocracy.com), in Ruby.
|
14
14
|
|
15
15
|
## How to contribute
|
16
16
|
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -40,6 +40,15 @@ require_relative 'baza-rb/version'
|
|
40
40
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
41
41
|
# License:: MIT
|
42
42
|
class BazaRb
|
43
|
+
# When the server failed (503).
|
44
|
+
class ServerFailure < StandardError; end
|
45
|
+
|
46
|
+
# When request timeout.
|
47
|
+
class TimedOut < StandardError; end
|
48
|
+
|
49
|
+
# Unexpected response arrived from the server.
|
50
|
+
class BadResponse < StandardError; end
|
51
|
+
|
43
52
|
# Ctor.
|
44
53
|
#
|
45
54
|
# @param [String] host Host name
|
@@ -88,7 +97,7 @@ class BazaRb
|
|
88
97
|
}
|
89
98
|
elapsed(@loog) do
|
90
99
|
ret =
|
91
|
-
with_retries(max_tries: @retries) do
|
100
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
92
101
|
checked(
|
93
102
|
Typhoeus::Request.put(
|
94
103
|
home.append('push').append(name).to_s,
|
@@ -126,7 +135,7 @@ class BazaRb
|
|
126
135
|
request.on_body do |chunk|
|
127
136
|
f.write(chunk)
|
128
137
|
end
|
129
|
-
with_retries(max_tries: @retries) do
|
138
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
130
139
|
request.run
|
131
140
|
end
|
132
141
|
checked(request.response)
|
@@ -148,7 +157,7 @@ class BazaRb
|
|
148
157
|
finished = false
|
149
158
|
elapsed(@loog) do
|
150
159
|
ret =
|
151
|
-
with_retries(max_tries: @retries) do
|
160
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
152
161
|
checked(
|
153
162
|
Typhoeus::Request.get(
|
154
163
|
home.append('finished').append(id).to_s,
|
@@ -172,7 +181,7 @@ class BazaRb
|
|
172
181
|
stdout = ''
|
173
182
|
elapsed(@loog) do
|
174
183
|
ret =
|
175
|
-
with_retries(max_tries: @retries) do
|
184
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
176
185
|
checked(
|
177
186
|
Typhoeus::Request.get(
|
178
187
|
home.append('stdout').append("#{id}.txt").to_s,
|
@@ -196,7 +205,7 @@ class BazaRb
|
|
196
205
|
code = 0
|
197
206
|
elapsed(@loog) do
|
198
207
|
ret =
|
199
|
-
with_retries(max_tries: @retries) do
|
208
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
200
209
|
checked(
|
201
210
|
Typhoeus::Request.get(
|
202
211
|
home.append('exit').append("#{id}.txt").to_s,
|
@@ -220,7 +229,7 @@ class BazaRb
|
|
220
229
|
verdict = 0
|
221
230
|
elapsed(@loog) do
|
222
231
|
ret =
|
223
|
-
with_retries(max_tries: @retries) do
|
232
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
224
233
|
checked(
|
225
234
|
Typhoeus::Request.get(
|
226
235
|
home.append('jobs').append(id).append('verified.txt').to_s,
|
@@ -243,7 +252,7 @@ class BazaRb
|
|
243
252
|
raise 'The "name" of the job may not be empty' if name.empty?
|
244
253
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
245
254
|
elapsed(@loog) do
|
246
|
-
with_retries(max_tries: @retries) do
|
255
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
247
256
|
checked(
|
248
257
|
Typhoeus::Request.get(
|
249
258
|
home.append('lock').append(name).add(owner:).to_s,
|
@@ -265,7 +274,7 @@ class BazaRb
|
|
265
274
|
raise 'The "name" of the job may not be empty' if name.empty?
|
266
275
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
267
276
|
elapsed(@loog) do
|
268
|
-
with_retries(max_tries: @retries) do
|
277
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
269
278
|
checked(
|
270
279
|
Typhoeus::Request.get(
|
271
280
|
home.append('unlock').append(name).add(owner:).to_s,
|
@@ -288,7 +297,7 @@ class BazaRb
|
|
288
297
|
job = 0
|
289
298
|
elapsed(@loog) do
|
290
299
|
ret =
|
291
|
-
with_retries(max_tries: @retries) do
|
300
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
292
301
|
checked(
|
293
302
|
Typhoeus::Request.get(
|
294
303
|
home.append('recent').append("#{name}.txt").to_s,
|
@@ -312,7 +321,7 @@ class BazaRb
|
|
312
321
|
exists = 0
|
313
322
|
elapsed(@loog) do
|
314
323
|
ret =
|
315
|
-
with_retries(max_tries: @retries) do
|
324
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
316
325
|
checked(
|
317
326
|
Typhoeus::Request.get(
|
318
327
|
home.append('exists').append(name).to_s,
|
@@ -338,7 +347,7 @@ class BazaRb
|
|
338
347
|
id = nil
|
339
348
|
elapsed(@loog) do
|
340
349
|
ret =
|
341
|
-
with_retries(max_tries: @retries) do
|
350
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
342
351
|
checked(
|
343
352
|
Typhoeus::Request.post(
|
344
353
|
home.append('durables').append('place').to_s,
|
@@ -370,7 +379,7 @@ class BazaRb
|
|
370
379
|
raise 'The "file" of the durable is nil' if file.nil?
|
371
380
|
raise "The file '#{file}' is absent" unless File.exist?(file)
|
372
381
|
elapsed(@loog) do
|
373
|
-
with_retries(max_tries: @retries) do
|
382
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
374
383
|
checked(
|
375
384
|
Typhoeus::Request.put(
|
376
385
|
home.append('durables').append(id).to_s,
|
@@ -408,7 +417,7 @@ class BazaRb
|
|
408
417
|
request.on_body do |chunk|
|
409
418
|
f.write(chunk)
|
410
419
|
end
|
411
|
-
with_retries(max_tries: @retries) do
|
420
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
412
421
|
request.run
|
413
422
|
end
|
414
423
|
checked(request.response)
|
@@ -427,7 +436,7 @@ class BazaRb
|
|
427
436
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
428
437
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
429
438
|
elapsed(@loog) do
|
430
|
-
with_retries(max_tries: @retries) do
|
439
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
431
440
|
checked(
|
432
441
|
Typhoeus::Request.get(
|
433
442
|
home.append('durables').append(id).append('lock').add(owner:).to_s,
|
@@ -450,7 +459,7 @@ class BazaRb
|
|
450
459
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
451
460
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
452
461
|
elapsed(@loog) do
|
453
|
-
with_retries(max_tries: @retries) do
|
462
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
454
463
|
checked(
|
455
464
|
Typhoeus::Request.get(
|
456
465
|
home.append('durables').append(id).append('unlock').add(owner:).to_s,
|
@@ -470,7 +479,6 @@ class BazaRb
|
|
470
479
|
# @return [Boolean] TRUE if job taken, otherwise false
|
471
480
|
def pop(owner, zip)
|
472
481
|
raise 'The "zip" of the job is nil' if zip.nil?
|
473
|
-
raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
|
474
482
|
success = false
|
475
483
|
FileUtils.rm_f(zip)
|
476
484
|
elapsed(@loog) do
|
@@ -487,7 +495,7 @@ class BazaRb
|
|
487
495
|
request.on_body do |chunk|
|
488
496
|
f.write(chunk)
|
489
497
|
end
|
490
|
-
with_retries(max_tries: @retries) do
|
498
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
491
499
|
request.run
|
492
500
|
end
|
493
501
|
ret = request.response
|
@@ -513,7 +521,7 @@ class BazaRb
|
|
513
521
|
raise 'The "zip" of the job is nil' if zip.nil?
|
514
522
|
raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
|
515
523
|
elapsed(@loog) do
|
516
|
-
with_retries(max_tries: @retries) do
|
524
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
517
525
|
checked(
|
518
526
|
Typhoeus::Request.put(
|
519
527
|
home.append('finish').add(id:).to_s,
|
@@ -531,6 +539,37 @@ class BazaRb
|
|
531
539
|
end
|
532
540
|
end
|
533
541
|
|
542
|
+
# Enter a valve.
|
543
|
+
#
|
544
|
+
# @param [String] name Name of the job
|
545
|
+
# @param [String] badge Unique badge of the valve
|
546
|
+
# @param [String] why The reason
|
547
|
+
# @param [nil|Integer] job The ID of the job
|
548
|
+
# @return [String] The result just calculated or retrieved
|
549
|
+
def enter(name, badge, why, job)
|
550
|
+
elapsed(@loog, intro: "Entered valve #{badge} to #{name}") do
|
551
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
552
|
+
ret = checked(
|
553
|
+
Typhoeus::Request.get(
|
554
|
+
home.append('valves').append('result').add(badge:).to_s,
|
555
|
+
headers:
|
556
|
+
),
|
557
|
+
[200, 204]
|
558
|
+
)
|
559
|
+
return ret.body if ret.code == 200
|
560
|
+
r = yield
|
561
|
+
uri = home.append('valves').append('add')
|
562
|
+
.add(name:)
|
563
|
+
.add(badge:)
|
564
|
+
.add(why:)
|
565
|
+
.add(result: r.to_s)
|
566
|
+
uri = uri.add(job:) unless job.nil?
|
567
|
+
checked(Typhoeus::Request.post(uri.to_s, headers:), 302)
|
568
|
+
r
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
534
573
|
private
|
535
574
|
|
536
575
|
def headers
|
@@ -571,14 +610,19 @@ class BazaRb
|
|
571
610
|
.scheme(@ssl ? 'https' : 'http')
|
572
611
|
end
|
573
612
|
|
613
|
+
# Check the HTTP response and return it.
|
614
|
+
#
|
615
|
+
# @param [Typhoeus::Response] ret The response
|
616
|
+
# @param [Array<Integer>] allowed List of acceptable HTTP codes
|
617
|
+
# @return [Typhoeus::Response] The same response
|
574
618
|
def checked(ret, allowed = [200])
|
575
619
|
allowed = [allowed] unless allowed.is_a?(Array)
|
576
620
|
mtd = (ret.request.original_options[:method] || '???').upcase
|
577
621
|
url = ret.effective_url
|
578
622
|
if ret.return_code == :operation_timedout
|
579
623
|
msg = "#{mtd} #{url} timed out in #{ret.total_time}s"
|
580
|
-
@loog.
|
581
|
-
raise msg
|
624
|
+
@loog.error(msg)
|
625
|
+
raise TimedOut, msg
|
582
626
|
end
|
583
627
|
log = "#{mtd} #{url} -> #{ret.code} (#{format('%0.2f', ret.total_time)}s)"
|
584
628
|
if allowed.include?(ret.code)
|
@@ -608,6 +652,7 @@ class BazaRb
|
|
608
652
|
when 0
|
609
653
|
msg += ', most likely an internal error'
|
610
654
|
end
|
611
|
-
|
655
|
+
@loog.error(msg)
|
656
|
+
raise ServerFailure, msg
|
612
657
|
end
|
613
658
|
end
|
data/test/test_baza-rb.rb
CHANGED
@@ -89,6 +89,16 @@ class TestBazaRb < Minitest::Test
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
def test_live_enter_valve
|
93
|
+
WebMock.enable_net_connect!
|
94
|
+
skip unless we_are_online
|
95
|
+
r = 'something'
|
96
|
+
n = fake_name
|
97
|
+
badge = fake_name
|
98
|
+
assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { r })
|
99
|
+
assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { nil })
|
100
|
+
end
|
101
|
+
|
92
102
|
def test_durable_place
|
93
103
|
WebMock.disable_net_connect!
|
94
104
|
stub_request(:post, 'https://example.org/durables/place').to_return(
|
@@ -180,7 +190,20 @@ class TestBazaRb < Minitest::Test
|
|
180
190
|
)
|
181
191
|
end
|
182
192
|
|
193
|
+
def test_push_with_server_failure
|
194
|
+
WebMock.disable_net_connect!
|
195
|
+
stub_request(:put, 'https://example.org/push/foo')
|
196
|
+
.to_return(status: 503, body: 'oops', headers: { 'X-Zerocracy-Failure': 'the failure' })
|
197
|
+
.to_raise('why second time?')
|
198
|
+
e = assert_raises { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
|
199
|
+
[
|
200
|
+
'Invalid response code #503',
|
201
|
+
'"the failure"'
|
202
|
+
].each { |t| assert(e.message.include?(t), "Can't find '#{t}' in #{e.message.inspect}") }
|
203
|
+
end
|
204
|
+
|
183
205
|
def test_real_http
|
206
|
+
WebMock.enable_net_connect!
|
184
207
|
req =
|
185
208
|
with_http_server(200, 'yes') do |baza|
|
186
209
|
baza.name_exists?('simple')
|
@@ -189,6 +212,7 @@ class TestBazaRb < Minitest::Test
|
|
189
212
|
end
|
190
213
|
|
191
214
|
def test_push_with_meta
|
215
|
+
WebMock.enable_net_connect!
|
192
216
|
req =
|
193
217
|
with_http_server(200, 'yes') do |baza|
|
194
218
|
baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
|
@@ -197,6 +221,7 @@ class TestBazaRb < Minitest::Test
|
|
197
221
|
end
|
198
222
|
|
199
223
|
def test_push_with_big_meta
|
224
|
+
WebMock.enable_net_connect!
|
200
225
|
req =
|
201
226
|
with_http_server(200, 'yes') do |baza|
|
202
227
|
baza.push(
|
@@ -213,6 +238,7 @@ class TestBazaRb < Minitest::Test
|
|
213
238
|
end
|
214
239
|
|
215
240
|
def test_push_compressed_content
|
241
|
+
WebMock.enable_net_connect!
|
216
242
|
req =
|
217
243
|
with_http_server(200, 'yes') do |baza|
|
218
244
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -224,6 +250,7 @@ class TestBazaRb < Minitest::Test
|
|
224
250
|
end
|
225
251
|
|
226
252
|
def test_push_compression_disabled
|
253
|
+
WebMock.enable_net_connect!
|
227
254
|
req =
|
228
255
|
with_http_server(200, 'yes', compress: false) do |baza|
|
229
256
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -280,7 +307,7 @@ class TestBazaRb < Minitest::Test
|
|
280
307
|
end
|
281
308
|
|
282
309
|
def fake_name
|
283
|
-
"fake
|
310
|
+
"fake#{SecureRandom.hex(8)}"
|
284
311
|
end
|
285
312
|
|
286
313
|
def we_are_online
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baza.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|