baza.rb 0.0.9 → 0.0.11
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 +97 -44
- data/test/test__helper.rb +2 -19
- data/test/test_baza-rb.rb +72 -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,42 @@ 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
|
+
id = nil
|
475
|
+
elapsed(@loog) do
|
476
|
+
ret =
|
477
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
478
|
+
checked(
|
479
|
+
Typhoeus::Request.post(
|
480
|
+
home.append('account').append('transfer').to_s,
|
481
|
+
body: {
|
482
|
+
'_csrf' => csrf,
|
483
|
+
'human' => recipient,
|
484
|
+
'amount' => amount.to_s,
|
485
|
+
'summary' => summary
|
486
|
+
},
|
487
|
+
headers:,
|
488
|
+
connecttimeout: @timeout,
|
489
|
+
timeout: @timeout
|
490
|
+
),
|
491
|
+
302
|
492
|
+
)
|
493
|
+
end
|
494
|
+
id = ret.headers['X-Zerocracy-ReceiptId'].to_i
|
495
|
+
throw :"Transferred ##{amount} to @#{recipient} at #{@host}"
|
496
|
+
end
|
497
|
+
id
|
498
|
+
end
|
499
|
+
|
475
500
|
# Pop job from the server.
|
476
501
|
#
|
477
502
|
# @param [String] owner Who is acting (could be any text)
|
@@ -511,13 +536,13 @@ class BazaRb
|
|
511
536
|
success
|
512
537
|
end
|
513
538
|
|
514
|
-
# Submit a ZIP
|
539
|
+
# Submit a ZIP archive to finish a job.
|
515
540
|
#
|
516
541
|
# @param [Integer] id The ID of the job on the server
|
517
542
|
# @param [String] zip The path to the ZIP file with the content of the archive
|
518
543
|
def finish(id, zip)
|
519
|
-
raise 'The
|
520
|
-
raise 'The
|
544
|
+
raise 'The ID of the job is nil' if id.nil?
|
545
|
+
raise 'The ID of the job must be a positive integer' unless id.positive?
|
521
546
|
raise 'The "zip" of the job is nil' if zip.nil?
|
522
547
|
raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
|
523
548
|
elapsed(@loog) do
|
@@ -559,17 +584,45 @@ class BazaRb
|
|
559
584
|
return ret.body if ret.code == 200
|
560
585
|
r = yield
|
561
586
|
uri = home.append('valves').append('add')
|
562
|
-
.add(name:)
|
563
|
-
.add(badge:)
|
564
|
-
.add(why:)
|
565
|
-
.add(result: r.to_s)
|
566
587
|
uri = uri.add(job:) unless job.nil?
|
567
|
-
checked(
|
588
|
+
checked(
|
589
|
+
Typhoeus::Request.post(
|
590
|
+
uri.to_s,
|
591
|
+
body: {
|
592
|
+
'_csrf' => csrf,
|
593
|
+
'name' => name,
|
594
|
+
'badge' => badge,
|
595
|
+
'why' => why,
|
596
|
+
'result' => r.to_s
|
597
|
+
},
|
598
|
+
headers:
|
599
|
+
),
|
600
|
+
302
|
601
|
+
)
|
568
602
|
r
|
569
603
|
end
|
570
604
|
end
|
571
605
|
end
|
572
606
|
|
607
|
+
# Get CSRF token from the server.
|
608
|
+
# @return [String] The token for this user
|
609
|
+
def csrf
|
610
|
+
token = nil
|
611
|
+
elapsed(@loog) do
|
612
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
613
|
+
token = checked(
|
614
|
+
Typhoeus::Request.get(
|
615
|
+
home.append('csrf').to_s,
|
616
|
+
headers:
|
617
|
+
),
|
618
|
+
200
|
619
|
+
).body
|
620
|
+
end
|
621
|
+
throw :"CSRF token retrieved (#{token.length} chars)"
|
622
|
+
end
|
623
|
+
token
|
624
|
+
end
|
625
|
+
|
573
626
|
private
|
574
627
|
|
575
628
|
def headers
|
@@ -595,7 +648,7 @@ class BazaRb
|
|
595
648
|
end
|
596
649
|
|
597
650
|
def gzip(data)
|
598
|
-
''.
|
651
|
+
(+'').tap do |result|
|
599
652
|
io = StringIO.new(result)
|
600
653
|
gz = Zlib::GzipWriter.new(io)
|
601
654
|
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,25 @@ 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(
|
102
|
+
status: 302, headers: { 'X-Zerocracy-ReceiptId' => '42' }
|
103
|
+
)
|
104
|
+
id = BazaRb.new('example.org', 443, '000').transfer('jeff', 42.50, 'for fun')
|
105
|
+
assert_equal(42, id)
|
106
|
+
end
|
107
|
+
|
102
108
|
def test_durable_place
|
103
109
|
WebMock.disable_net_connect!
|
110
|
+
stub_request(:get, 'https://example.org/csrf').to_return(body: 'token')
|
104
111
|
stub_request(:post, 'https://example.org/durables/place').to_return(
|
105
112
|
status: 302, headers: { 'X-Zerocracy-DurableId' => '42' }
|
106
113
|
)
|
@@ -126,8 +133,8 @@ class TestBazaRb < Minitest::Test
|
|
126
133
|
WebMock.disable_net_connect!
|
127
134
|
stub_request(:get, 'https://example.org/pop?owner=me').to_return(status: 204)
|
128
135
|
Tempfile.open do |zip|
|
129
|
-
|
130
|
-
|
136
|
+
refute(BazaRb.new('example.org', 443, '000').pop('me', zip.path))
|
137
|
+
refute_path_exists(zip.path)
|
131
138
|
end
|
132
139
|
end
|
133
140
|
|
@@ -165,8 +172,8 @@ class TestBazaRb < Minitest::Test
|
|
165
172
|
stub_request(:get, 'https://example.org/exit/42.txt').to_return(
|
166
173
|
status: 200, body: '0'
|
167
174
|
)
|
168
|
-
|
169
|
-
BazaRb.new('example.org', 443, '000').exit_code(42)
|
175
|
+
assert_predicate(
|
176
|
+
BazaRb.new('example.org', 443, '000').exit_code(42), :zero?
|
170
177
|
)
|
171
178
|
end
|
172
179
|
|
@@ -175,8 +182,8 @@ class TestBazaRb < Minitest::Test
|
|
175
182
|
stub_request(:get, 'https://example.org/stdout/42.txt').to_return(
|
176
183
|
status: 200, body: 'hello!'
|
177
184
|
)
|
178
|
-
|
179
|
-
|
185
|
+
refute_empty(
|
186
|
+
BazaRb.new('example.org', 443, '000').stdout(42)
|
180
187
|
)
|
181
188
|
end
|
182
189
|
|
@@ -190,20 +197,35 @@ class TestBazaRb < Minitest::Test
|
|
190
197
|
)
|
191
198
|
end
|
192
199
|
|
200
|
+
def test_simple_lock_success
|
201
|
+
WebMock.disable_net_connect!
|
202
|
+
stub_request(:get, 'https://example.org/lock/name?owner=owner').to_return(status: 302)
|
203
|
+
BazaRb.new('example.org', 443, '000').lock('name', 'owner')
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_simple_lock_failure
|
207
|
+
WebMock.disable_net_connect!
|
208
|
+
stub_request(:get, 'https://example.org/lock/name?owner=owner').to_return(status: 409)
|
209
|
+
assert_raises(StandardError) do
|
210
|
+
BazaRb.new('example.org', 443, '000').lock('name', 'owner')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
193
214
|
def test_push_with_server_failure
|
194
215
|
WebMock.disable_net_connect!
|
195
216
|
stub_request(:put, 'https://example.org/push/foo')
|
196
217
|
.to_return(status: 503, body: 'oops', headers: { 'X-Zerocracy-Failure': 'the failure' })
|
197
218
|
.to_raise('why second time?')
|
198
|
-
e = assert_raises { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
|
219
|
+
e = assert_raises(StandardError) { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
|
199
220
|
[
|
200
221
|
'Invalid response code #503',
|
201
222
|
'"the failure"'
|
202
|
-
].each { |t|
|
223
|
+
].each { |t| assert_includes(e.message, t, "Can't find '#{t}' in #{e.message.inspect}") }
|
203
224
|
end
|
204
225
|
|
205
226
|
def test_real_http
|
206
227
|
WebMock.enable_net_connect!
|
228
|
+
skip('We are offline') unless we_are_online
|
207
229
|
req =
|
208
230
|
with_http_server(200, 'yes') do |baza|
|
209
231
|
baza.name_exists?('simple')
|
@@ -213,6 +235,7 @@ class TestBazaRb < Minitest::Test
|
|
213
235
|
|
214
236
|
def test_push_with_meta
|
215
237
|
WebMock.enable_net_connect!
|
238
|
+
skip('We are offline') unless we_are_online
|
216
239
|
req =
|
217
240
|
with_http_server(200, 'yes') do |baza|
|
218
241
|
baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
|
@@ -222,6 +245,7 @@ class TestBazaRb < Minitest::Test
|
|
222
245
|
|
223
246
|
def test_push_with_big_meta
|
224
247
|
WebMock.enable_net_connect!
|
248
|
+
skip('We are offline') unless we_are_online
|
225
249
|
req =
|
226
250
|
with_http_server(200, 'yes') do |baza|
|
227
251
|
baza.push(
|
@@ -239,6 +263,7 @@ class TestBazaRb < Minitest::Test
|
|
239
263
|
|
240
264
|
def test_push_compressed_content
|
241
265
|
WebMock.enable_net_connect!
|
266
|
+
skip('We are offline') unless we_are_online
|
242
267
|
req =
|
243
268
|
with_http_server(200, 'yes') do |baza|
|
244
269
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -251,6 +276,7 @@ class TestBazaRb < Minitest::Test
|
|
251
276
|
|
252
277
|
def test_push_compression_disabled
|
253
278
|
WebMock.enable_net_connect!
|
279
|
+
skip('We are offline') unless we_are_online
|
254
280
|
req =
|
255
281
|
with_http_server(200, 'yes', compress: false) do |baza|
|
256
282
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -261,6 +287,7 @@ class TestBazaRb < Minitest::Test
|
|
261
287
|
|
262
288
|
def test_with_very_short_timeout
|
263
289
|
WebMock.enable_net_connect!
|
290
|
+
skip('We are offline') unless we_are_online
|
264
291
|
host = '127.0.0.1'
|
265
292
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
266
293
|
server = TCPServer.new(host, port)
|
@@ -274,10 +301,10 @@ class TestBazaRb < Minitest::Test
|
|
274
301
|
socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nabc"
|
275
302
|
socket.close
|
276
303
|
end
|
277
|
-
|
278
|
-
assert_raises do
|
304
|
+
assert_includes(
|
305
|
+
assert_raises(StandardError) do
|
279
306
|
BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
|
280
|
-
end.message
|
307
|
+
end.message, 'timed out in'
|
281
308
|
)
|
282
309
|
t.join
|
283
310
|
end
|
@@ -288,6 +315,7 @@ class TestBazaRb < Minitest::Test
|
|
288
315
|
def with_http_server(code, response, opts = {})
|
289
316
|
opts = { ssl: false, timeout: 1 }.merge(opts)
|
290
317
|
WebMock.enable_net_connect!
|
318
|
+
skip('We are offline') unless we_are_online
|
291
319
|
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
292
320
|
host = '127.0.0.1'
|
293
321
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
@@ -311,6 +339,6 @@ class TestBazaRb < Minitest::Test
|
|
311
339
|
end
|
312
340
|
|
313
341
|
def we_are_online
|
314
|
-
Net::Ping::External.new('8.8.8.8').ping?
|
342
|
+
@we_are_online ||= Net::Ping::External.new('8.8.8.8').ping?
|
315
343
|
end
|
316
344
|
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.11
|
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-29 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: []
|