baza.rb 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +4 -20
- data/.github/workflows/codecov.yml +8 -22
- data/.github/workflows/copyrights.yml +9 -20
- data/.github/workflows/markdown-lint.yml +4 -19
- data/.github/workflows/pdd.yml +4 -19
- data/.github/workflows/rake.yml +6 -22
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/xcop.yml +8 -19
- data/.github/workflows/yamllint.yml +4 -19
- data/.gitignore +7 -5
- data/.rubocop.yml +8 -20
- data/.rultor.yml +4 -20
- data/.simplecov +2 -19
- data/.yamllint.yml +2 -19
- data/Gemfile +16 -31
- data/Gemfile.lock +81 -160
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/REUSE.toml +34 -0
- data/Rakefile +3 -29
- data/baza.rb.gemspec +2 -19
- data/lib/baza-rb/version.rb +3 -20
- data/lib/baza-rb.rb +93 -44
- data/test/test__helper.rb +2 -19
- data/test/test_baza-rb.rb +69 -44
- metadata +6 -6
data/lib/baza-rb.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Zerocracy
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'base64'
|
24
7
|
require 'elapsed'
|
@@ -26,8 +9,11 @@ require 'fileutils'
|
|
26
9
|
require 'iri'
|
27
10
|
require 'loog'
|
28
11
|
require 'retries'
|
12
|
+
require 'stringio'
|
29
13
|
require 'tago'
|
14
|
+
require 'tempfile'
|
30
15
|
require 'typhoeus'
|
16
|
+
require 'zlib'
|
31
17
|
require_relative 'baza-rb/version'
|
32
18
|
|
33
19
|
# Interface to the API of zerocracy.com.
|
@@ -37,7 +23,7 @@ require_relative 'baza-rb/version'
|
|
37
23
|
# results returned.
|
38
24
|
#
|
39
25
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
40
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
26
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
41
27
|
# License:: MIT
|
42
28
|
class BazaRb
|
43
29
|
# When the server failed (503).
|
@@ -87,7 +73,7 @@ class BazaRb
|
|
87
73
|
'Content-Length' => data.size
|
88
74
|
)
|
89
75
|
unless meta.empty?
|
90
|
-
hdrs = hdrs.merge('X-Zerocracy-Meta' => meta.map { |v| Base64.encode64(v).
|
76
|
+
hdrs = hdrs.merge('X-Zerocracy-Meta' => meta.map { |v| Base64.encode64(v).delete("\n") }.join(' '))
|
91
77
|
end
|
92
78
|
params = {
|
93
79
|
connecttimeout: @timeout,
|
@@ -118,7 +104,7 @@ class BazaRb
|
|
118
104
|
def pull(id)
|
119
105
|
raise 'The ID of the job is nil' if id.nil?
|
120
106
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
121
|
-
data =
|
107
|
+
data = ''
|
122
108
|
elapsed(@loog) do
|
123
109
|
Tempfile.open do |file|
|
124
110
|
File.open(file, 'wb') do |f|
|
@@ -226,7 +212,7 @@ class BazaRb
|
|
226
212
|
def verified(id)
|
227
213
|
raise 'The ID of the job is nil' if id.nil?
|
228
214
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
229
|
-
verdict =
|
215
|
+
verdict = ''
|
230
216
|
elapsed(@loog) do
|
231
217
|
ret =
|
232
218
|
with_retries(max_tries: @retries, rescue: TimedOut) do
|
@@ -252,16 +238,18 @@ class BazaRb
|
|
252
238
|
raise 'The "name" of the job may not be empty' if name.empty?
|
253
239
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
254
240
|
elapsed(@loog) do
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
241
|
+
ret =
|
242
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
243
|
+
checked(
|
244
|
+
Typhoeus::Request.get(
|
245
|
+
home.append('lock').append(name).add(owner:).to_s,
|
246
|
+
headers:
|
247
|
+
),
|
248
|
+
[302, 409]
|
249
|
+
)
|
250
|
+
end
|
251
|
+
throw :"Job name '#{name}' locked at #{@host}" if ret.code == 302
|
252
|
+
raise "Failed to lock '#{name}' job at #{@host}, it's most probably already locked"
|
265
253
|
end
|
266
254
|
end
|
267
255
|
|
@@ -294,7 +282,7 @@ class BazaRb
|
|
294
282
|
def recent(name)
|
295
283
|
raise 'The "name" of the job is nil' if name.nil?
|
296
284
|
raise 'The "name" of the job may not be empty' if name.empty?
|
297
|
-
job =
|
285
|
+
job = nil
|
298
286
|
elapsed(@loog) do
|
299
287
|
ret =
|
300
288
|
with_retries(max_tries: @retries, rescue: TimedOut) do
|
@@ -318,7 +306,7 @@ class BazaRb
|
|
318
306
|
def name_exists?(name)
|
319
307
|
raise 'The "name" of the job is nil' if name.nil?
|
320
308
|
raise 'The "name" of the job may not be empty' if name.empty?
|
321
|
-
exists =
|
309
|
+
exists = false
|
322
310
|
elapsed(@loog) do
|
323
311
|
ret =
|
324
312
|
with_retries(max_tries: @retries, rescue: TimedOut) do
|
@@ -352,6 +340,7 @@ class BazaRb
|
|
352
340
|
Typhoeus::Request.post(
|
353
341
|
home.append('durables').append('place').to_s,
|
354
342
|
body: {
|
343
|
+
'_csrf' => csrf,
|
355
344
|
'jname' => jname,
|
356
345
|
'file' => File.basename(file),
|
357
346
|
'zip' => File.open(file, 'rb')
|
@@ -472,6 +461,38 @@ class BazaRb
|
|
472
461
|
end
|
473
462
|
end
|
474
463
|
|
464
|
+
# Transfer some funds to another user.
|
465
|
+
#
|
466
|
+
# @param [String] recipient GitHub name (e.g. "yegor256") of the recipient
|
467
|
+
# @param [Float] amount The amount in Z/USDT (not zents!)
|
468
|
+
# @param [String] summary The description of the payment
|
469
|
+
def transfer(recipient, amount, summary)
|
470
|
+
raise 'The "recipient" is nil' if recipient.nil?
|
471
|
+
raise 'The "amount" is nil' if amount.nil?
|
472
|
+
raise 'The "amount" must be Float' unless amount.is_a?(Float)
|
473
|
+
raise 'The "summary" is nil' if summary.nil?
|
474
|
+
elapsed(@loog) do
|
475
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
476
|
+
checked(
|
477
|
+
Typhoeus::Request.post(
|
478
|
+
home.append('account').append('transfer').to_s,
|
479
|
+
body: {
|
480
|
+
'_csrf' => csrf,
|
481
|
+
'human' => recipient,
|
482
|
+
'amount' => amount.to_s,
|
483
|
+
'summary' => summary
|
484
|
+
},
|
485
|
+
headers:,
|
486
|
+
connecttimeout: @timeout,
|
487
|
+
timeout: @timeout
|
488
|
+
),
|
489
|
+
302
|
490
|
+
)
|
491
|
+
end
|
492
|
+
throw :"Transferred ##{amount} to @#{recipient} at #{@host}"
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
475
496
|
# Pop job from the server.
|
476
497
|
#
|
477
498
|
# @param [String] owner Who is acting (could be any text)
|
@@ -511,13 +532,13 @@ class BazaRb
|
|
511
532
|
success
|
512
533
|
end
|
513
534
|
|
514
|
-
# Submit a ZIP
|
535
|
+
# Submit a ZIP archive to finish a job.
|
515
536
|
#
|
516
537
|
# @param [Integer] id The ID of the job on the server
|
517
538
|
# @param [String] zip The path to the ZIP file with the content of the archive
|
518
539
|
def finish(id, zip)
|
519
|
-
raise 'The
|
520
|
-
raise 'The
|
540
|
+
raise 'The ID of the job is nil' if id.nil?
|
541
|
+
raise 'The ID of the job must be a positive integer' unless id.positive?
|
521
542
|
raise 'The "zip" of the job is nil' if zip.nil?
|
522
543
|
raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
|
523
544
|
elapsed(@loog) do
|
@@ -559,17 +580,45 @@ class BazaRb
|
|
559
580
|
return ret.body if ret.code == 200
|
560
581
|
r = yield
|
561
582
|
uri = home.append('valves').append('add')
|
562
|
-
.add(name:)
|
563
|
-
.add(badge:)
|
564
|
-
.add(why:)
|
565
|
-
.add(result: r.to_s)
|
566
583
|
uri = uri.add(job:) unless job.nil?
|
567
|
-
checked(
|
584
|
+
checked(
|
585
|
+
Typhoeus::Request.post(
|
586
|
+
uri.to_s,
|
587
|
+
body: {
|
588
|
+
'_csrf' => csrf,
|
589
|
+
'name' => name,
|
590
|
+
'badge' => badge,
|
591
|
+
'why' => why,
|
592
|
+
'result' => r.to_s
|
593
|
+
},
|
594
|
+
headers:
|
595
|
+
),
|
596
|
+
302
|
597
|
+
)
|
568
598
|
r
|
569
599
|
end
|
570
600
|
end
|
571
601
|
end
|
572
602
|
|
603
|
+
# Get CSRF token from the server.
|
604
|
+
# @return [String] The token for this user
|
605
|
+
def csrf
|
606
|
+
token = nil
|
607
|
+
elapsed(@loog) do
|
608
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
609
|
+
token = checked(
|
610
|
+
Typhoeus::Request.get(
|
611
|
+
home.append('csrf').to_s,
|
612
|
+
headers:
|
613
|
+
),
|
614
|
+
200
|
615
|
+
).body
|
616
|
+
end
|
617
|
+
throw :"CSRF token retrieved (#{token.length} chars)"
|
618
|
+
end
|
619
|
+
token
|
620
|
+
end
|
621
|
+
|
573
622
|
private
|
574
623
|
|
575
624
|
def headers
|
@@ -595,7 +644,7 @@ class BazaRb
|
|
595
644
|
end
|
596
645
|
|
597
646
|
def gzip(data)
|
598
|
-
''.
|
647
|
+
(+'').tap do |result|
|
599
648
|
io = StringIO.new(result)
|
600
649
|
gz = Zlib::GzipWriter.new(io)
|
601
650
|
gz.write(data)
|
data/test/test__helper.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Zerocracy
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
$stdout.sync = true
|
24
7
|
|
data/test/test_baza-rb.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Zerocracy
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'factbase'
|
24
7
|
require 'loog'
|
@@ -38,45 +21,52 @@ require_relative '../lib/baza-rb'
|
|
38
21
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
39
22
|
# License:: MIT
|
40
23
|
class TestBazaRb < Minitest::Test
|
24
|
+
# The token to use for testing:
|
41
25
|
TOKEN = '00000000-0000-0000-0000-000000000000'
|
26
|
+
|
27
|
+
# The host of the production platform:
|
42
28
|
HOST = 'api.zerocracy.com'
|
29
|
+
|
30
|
+
# The HTTPS port to use:
|
43
31
|
PORT = 443
|
32
|
+
|
33
|
+
# Live agent:
|
44
34
|
LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::VERBOSE)
|
45
35
|
|
46
36
|
def test_live_push
|
47
37
|
WebMock.enable_net_connect!
|
48
|
-
skip unless we_are_online
|
38
|
+
skip('We are offline') unless we_are_online
|
49
39
|
fb = Factbase.new
|
50
40
|
fb.insert.foo = 'test-' * 10_000
|
51
41
|
fb.insert
|
52
42
|
n = fake_name
|
53
|
-
|
43
|
+
assert_predicate(LIVE.push(n, fb.export, []), :positive?)
|
54
44
|
assert(LIVE.name_exists?(n))
|
55
|
-
|
45
|
+
assert_predicate(LIVE.recent(n), :positive?)
|
56
46
|
id = LIVE.recent(n)
|
57
47
|
wait_for(60) { LIVE.finished?(id) }
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
refute_nil(LIVE.pull(id))
|
49
|
+
refute_nil(LIVE.stdout(id))
|
50
|
+
refute_nil(LIVE.exit_code(id))
|
51
|
+
refute_nil(LIVE.verified(id))
|
62
52
|
owner = 'baza.rb testing'
|
63
|
-
|
64
|
-
|
53
|
+
refute_nil(LIVE.lock(n, owner))
|
54
|
+
refute_nil(LIVE.unlock(n, owner))
|
65
55
|
end
|
66
56
|
|
67
57
|
def test_live_push_no_compression
|
68
58
|
WebMock.enable_net_connect!
|
69
|
-
skip unless we_are_online
|
59
|
+
skip('We are offline') unless we_are_online
|
70
60
|
fb = Factbase.new
|
71
61
|
fb.insert.foo = 'test-' * 10_000
|
72
62
|
fb.insert
|
73
63
|
baza = BazaRb.new(HOST, PORT, TOKEN, compress: false)
|
74
|
-
|
64
|
+
assert_predicate(baza.push(fake_name, fb.export, []), :positive?)
|
75
65
|
end
|
76
66
|
|
77
67
|
def test_live_durable_lock_unlock
|
78
68
|
WebMock.enable_net_connect!
|
79
|
-
skip unless we_are_online
|
69
|
+
skip('We are offline') unless we_are_online
|
80
70
|
Dir.mktmpdir do |dir|
|
81
71
|
file = File.join(dir, "#{fake_name}.bin")
|
82
72
|
File.binwrite(file, 'hello')
|
@@ -91,7 +81,7 @@ class TestBazaRb < Minitest::Test
|
|
91
81
|
|
92
82
|
def test_live_enter_valve
|
93
83
|
WebMock.enable_net_connect!
|
94
|
-
skip unless we_are_online
|
84
|
+
skip('We are offline') unless we_are_online
|
95
85
|
r = 'something'
|
96
86
|
n = fake_name
|
97
87
|
badge = fake_name
|
@@ -99,8 +89,22 @@ class TestBazaRb < Minitest::Test
|
|
99
89
|
assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { nil })
|
100
90
|
end
|
101
91
|
|
92
|
+
def test_get_csrf_token
|
93
|
+
WebMock.enable_net_connect!
|
94
|
+
skip('We are offline') unless we_are_online
|
95
|
+
assert_operator(LIVE.csrf.length, :>, 10)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_transfer_payment
|
99
|
+
WebMock.disable_net_connect!
|
100
|
+
stub_request(:get, 'https://example.org/csrf').to_return(body: 'token')
|
101
|
+
stub_request(:post, 'https://example.org/account/transfer').to_return(status: 302)
|
102
|
+
BazaRb.new('example.org', 443, '000').transfer('jeff', 42.50, 'for fun')
|
103
|
+
end
|
104
|
+
|
102
105
|
def test_durable_place
|
103
106
|
WebMock.disable_net_connect!
|
107
|
+
stub_request(:get, 'https://example.org/csrf').to_return(body: 'token')
|
104
108
|
stub_request(:post, 'https://example.org/durables/place').to_return(
|
105
109
|
status: 302, headers: { 'X-Zerocracy-DurableId' => '42' }
|
106
110
|
)
|
@@ -126,8 +130,8 @@ class TestBazaRb < Minitest::Test
|
|
126
130
|
WebMock.disable_net_connect!
|
127
131
|
stub_request(:get, 'https://example.org/pop?owner=me').to_return(status: 204)
|
128
132
|
Tempfile.open do |zip|
|
129
|
-
|
130
|
-
|
133
|
+
refute(BazaRb.new('example.org', 443, '000').pop('me', zip.path))
|
134
|
+
refute_path_exists(zip.path)
|
131
135
|
end
|
132
136
|
end
|
133
137
|
|
@@ -165,8 +169,8 @@ class TestBazaRb < Minitest::Test
|
|
165
169
|
stub_request(:get, 'https://example.org/exit/42.txt').to_return(
|
166
170
|
status: 200, body: '0'
|
167
171
|
)
|
168
|
-
|
169
|
-
BazaRb.new('example.org', 443, '000').exit_code(42)
|
172
|
+
assert_predicate(
|
173
|
+
BazaRb.new('example.org', 443, '000').exit_code(42), :zero?
|
170
174
|
)
|
171
175
|
end
|
172
176
|
|
@@ -175,8 +179,8 @@ class TestBazaRb < Minitest::Test
|
|
175
179
|
stub_request(:get, 'https://example.org/stdout/42.txt').to_return(
|
176
180
|
status: 200, body: 'hello!'
|
177
181
|
)
|
178
|
-
|
179
|
-
|
182
|
+
refute_empty(
|
183
|
+
BazaRb.new('example.org', 443, '000').stdout(42)
|
180
184
|
)
|
181
185
|
end
|
182
186
|
|
@@ -190,20 +194,35 @@ class TestBazaRb < Minitest::Test
|
|
190
194
|
)
|
191
195
|
end
|
192
196
|
|
197
|
+
def test_simple_lock_success
|
198
|
+
WebMock.disable_net_connect!
|
199
|
+
stub_request(:get, 'https://example.org/lock/name?owner=owner').to_return(status: 302)
|
200
|
+
BazaRb.new('example.org', 443, '000').lock('name', 'owner')
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_simple_lock_failure
|
204
|
+
WebMock.disable_net_connect!
|
205
|
+
stub_request(:get, 'https://example.org/lock/name?owner=owner').to_return(status: 409)
|
206
|
+
assert_raises(StandardError) do
|
207
|
+
BazaRb.new('example.org', 443, '000').lock('name', 'owner')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
193
211
|
def test_push_with_server_failure
|
194
212
|
WebMock.disable_net_connect!
|
195
213
|
stub_request(:put, 'https://example.org/push/foo')
|
196
214
|
.to_return(status: 503, body: 'oops', headers: { 'X-Zerocracy-Failure': 'the failure' })
|
197
215
|
.to_raise('why second time?')
|
198
|
-
e = assert_raises { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
|
216
|
+
e = assert_raises(StandardError) { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
|
199
217
|
[
|
200
218
|
'Invalid response code #503',
|
201
219
|
'"the failure"'
|
202
|
-
].each { |t|
|
220
|
+
].each { |t| assert_includes(e.message, t, "Can't find '#{t}' in #{e.message.inspect}") }
|
203
221
|
end
|
204
222
|
|
205
223
|
def test_real_http
|
206
224
|
WebMock.enable_net_connect!
|
225
|
+
skip('We are offline') unless we_are_online
|
207
226
|
req =
|
208
227
|
with_http_server(200, 'yes') do |baza|
|
209
228
|
baza.name_exists?('simple')
|
@@ -213,6 +232,7 @@ class TestBazaRb < Minitest::Test
|
|
213
232
|
|
214
233
|
def test_push_with_meta
|
215
234
|
WebMock.enable_net_connect!
|
235
|
+
skip('We are offline') unless we_are_online
|
216
236
|
req =
|
217
237
|
with_http_server(200, 'yes') do |baza|
|
218
238
|
baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
|
@@ -222,6 +242,7 @@ class TestBazaRb < Minitest::Test
|
|
222
242
|
|
223
243
|
def test_push_with_big_meta
|
224
244
|
WebMock.enable_net_connect!
|
245
|
+
skip('We are offline') unless we_are_online
|
225
246
|
req =
|
226
247
|
with_http_server(200, 'yes') do |baza|
|
227
248
|
baza.push(
|
@@ -239,6 +260,7 @@ class TestBazaRb < Minitest::Test
|
|
239
260
|
|
240
261
|
def test_push_compressed_content
|
241
262
|
WebMock.enable_net_connect!
|
263
|
+
skip('We are offline') unless we_are_online
|
242
264
|
req =
|
243
265
|
with_http_server(200, 'yes') do |baza|
|
244
266
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -251,6 +273,7 @@ class TestBazaRb < Minitest::Test
|
|
251
273
|
|
252
274
|
def test_push_compression_disabled
|
253
275
|
WebMock.enable_net_connect!
|
276
|
+
skip('We are offline') unless we_are_online
|
254
277
|
req =
|
255
278
|
with_http_server(200, 'yes', compress: false) do |baza|
|
256
279
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -261,6 +284,7 @@ class TestBazaRb < Minitest::Test
|
|
261
284
|
|
262
285
|
def test_with_very_short_timeout
|
263
286
|
WebMock.enable_net_connect!
|
287
|
+
skip('We are offline') unless we_are_online
|
264
288
|
host = '127.0.0.1'
|
265
289
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
266
290
|
server = TCPServer.new(host, port)
|
@@ -274,10 +298,10 @@ class TestBazaRb < Minitest::Test
|
|
274
298
|
socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nabc"
|
275
299
|
socket.close
|
276
300
|
end
|
277
|
-
|
278
|
-
assert_raises do
|
301
|
+
assert_includes(
|
302
|
+
assert_raises(StandardError) do
|
279
303
|
BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
|
280
|
-
end.message
|
304
|
+
end.message, 'timed out in'
|
281
305
|
)
|
282
306
|
t.join
|
283
307
|
end
|
@@ -288,6 +312,7 @@ class TestBazaRb < Minitest::Test
|
|
288
312
|
def with_http_server(code, response, opts = {})
|
289
313
|
opts = { ssl: false, timeout: 1 }.merge(opts)
|
290
314
|
WebMock.enable_net_connect!
|
315
|
+
skip('We are offline') unless we_are_online
|
291
316
|
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
292
317
|
host = '127.0.0.1'
|
293
318
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
@@ -311,6 +336,6 @@ class TestBazaRb < Minitest::Test
|
|
311
336
|
end
|
312
337
|
|
313
338
|
def we_are_online
|
314
|
-
Net::Ping::External.new('8.8.8.8').ping?
|
339
|
+
@we_are_online ||= Net::Ping::External.new('8.8.8.8').ping?
|
315
340
|
end
|
316
341
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-28 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: backtrace
|
@@ -182,6 +181,7 @@ files:
|
|
182
181
|
- ".github/workflows/markdown-lint.yml"
|
183
182
|
- ".github/workflows/pdd.yml"
|
184
183
|
- ".github/workflows/rake.yml"
|
184
|
+
- ".github/workflows/reuse.yml"
|
185
185
|
- ".github/workflows/xcop.yml"
|
186
186
|
- ".github/workflows/yamllint.yml"
|
187
187
|
- ".gitignore"
|
@@ -193,7 +193,9 @@ files:
|
|
193
193
|
- Gemfile
|
194
194
|
- Gemfile.lock
|
195
195
|
- LICENSE.txt
|
196
|
+
- LICENSES/MIT.txt
|
196
197
|
- README.md
|
198
|
+
- REUSE.toml
|
197
199
|
- Rakefile
|
198
200
|
- baza.rb.gemspec
|
199
201
|
- lib/baza-rb.rb
|
@@ -206,7 +208,6 @@ licenses:
|
|
206
208
|
- MIT
|
207
209
|
metadata:
|
208
210
|
rubygems_mfa_required: 'true'
|
209
|
-
post_install_message:
|
210
211
|
rdoc_options:
|
211
212
|
- "--charset=UTF-8"
|
212
213
|
require_paths:
|
@@ -222,8 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
223
|
- !ruby/object:Gem::Version
|
223
224
|
version: '0'
|
224
225
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
226
|
-
signing_key:
|
226
|
+
rubygems_version: 3.6.2
|
227
227
|
specification_version: 4
|
228
228
|
summary: Zerocracy API Ruby Client
|
229
229
|
test_files: []
|