baza.rb 0.0.8 → 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 +5 -21
- data/.github/workflows/codecov.yml +9 -23
- data/.github/workflows/copyrights.yml +10 -21
- data/.github/workflows/markdown-lint.yml +5 -20
- data/.github/workflows/pdd.yml +5 -20
- data/.github/workflows/rake.yml +6 -22
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/xcop.yml +9 -20
- data/.github/workflows/yamllint.yml +5 -20
- 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 +84 -165
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +1 -1
- 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 +153 -59
- data/test/test__helper.rb +2 -19
- data/test/test_baza-rb.rb +94 -42
- metadata +6 -6
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')
|
@@ -89,8 +79,32 @@ class TestBazaRb < Minitest::Test
|
|
89
79
|
end
|
90
80
|
end
|
91
81
|
|
82
|
+
def test_live_enter_valve
|
83
|
+
WebMock.enable_net_connect!
|
84
|
+
skip('We are offline') unless we_are_online
|
85
|
+
r = 'something'
|
86
|
+
n = fake_name
|
87
|
+
badge = fake_name
|
88
|
+
assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { r })
|
89
|
+
assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { nil })
|
90
|
+
end
|
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
|
+
|
92
105
|
def test_durable_place
|
93
106
|
WebMock.disable_net_connect!
|
107
|
+
stub_request(:get, 'https://example.org/csrf').to_return(body: 'token')
|
94
108
|
stub_request(:post, 'https://example.org/durables/place').to_return(
|
95
109
|
status: 302, headers: { 'X-Zerocracy-DurableId' => '42' }
|
96
110
|
)
|
@@ -116,8 +130,8 @@ class TestBazaRb < Minitest::Test
|
|
116
130
|
WebMock.disable_net_connect!
|
117
131
|
stub_request(:get, 'https://example.org/pop?owner=me').to_return(status: 204)
|
118
132
|
Tempfile.open do |zip|
|
119
|
-
|
120
|
-
|
133
|
+
refute(BazaRb.new('example.org', 443, '000').pop('me', zip.path))
|
134
|
+
refute_path_exists(zip.path)
|
121
135
|
end
|
122
136
|
end
|
123
137
|
|
@@ -155,8 +169,8 @@ class TestBazaRb < Minitest::Test
|
|
155
169
|
stub_request(:get, 'https://example.org/exit/42.txt').to_return(
|
156
170
|
status: 200, body: '0'
|
157
171
|
)
|
158
|
-
|
159
|
-
BazaRb.new('example.org', 443, '000').exit_code(42)
|
172
|
+
assert_predicate(
|
173
|
+
BazaRb.new('example.org', 443, '000').exit_code(42), :zero?
|
160
174
|
)
|
161
175
|
end
|
162
176
|
|
@@ -165,8 +179,8 @@ class TestBazaRb < Minitest::Test
|
|
165
179
|
stub_request(:get, 'https://example.org/stdout/42.txt').to_return(
|
166
180
|
status: 200, body: 'hello!'
|
167
181
|
)
|
168
|
-
|
169
|
-
|
182
|
+
refute_empty(
|
183
|
+
BazaRb.new('example.org', 443, '000').stdout(42)
|
170
184
|
)
|
171
185
|
end
|
172
186
|
|
@@ -180,7 +194,35 @@ class TestBazaRb < Minitest::Test
|
|
180
194
|
)
|
181
195
|
end
|
182
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
|
+
|
211
|
+
def test_push_with_server_failure
|
212
|
+
WebMock.disable_net_connect!
|
213
|
+
stub_request(:put, 'https://example.org/push/foo')
|
214
|
+
.to_return(status: 503, body: 'oops', headers: { 'X-Zerocracy-Failure': 'the failure' })
|
215
|
+
.to_raise('why second time?')
|
216
|
+
e = assert_raises(StandardError) { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
|
217
|
+
[
|
218
|
+
'Invalid response code #503',
|
219
|
+
'"the failure"'
|
220
|
+
].each { |t| assert_includes(e.message, t, "Can't find '#{t}' in #{e.message.inspect}") }
|
221
|
+
end
|
222
|
+
|
183
223
|
def test_real_http
|
224
|
+
WebMock.enable_net_connect!
|
225
|
+
skip('We are offline') unless we_are_online
|
184
226
|
req =
|
185
227
|
with_http_server(200, 'yes') do |baza|
|
186
228
|
baza.name_exists?('simple')
|
@@ -189,6 +231,8 @@ class TestBazaRb < Minitest::Test
|
|
189
231
|
end
|
190
232
|
|
191
233
|
def test_push_with_meta
|
234
|
+
WebMock.enable_net_connect!
|
235
|
+
skip('We are offline') unless we_are_online
|
192
236
|
req =
|
193
237
|
with_http_server(200, 'yes') do |baza|
|
194
238
|
baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
|
@@ -197,6 +241,8 @@ class TestBazaRb < Minitest::Test
|
|
197
241
|
end
|
198
242
|
|
199
243
|
def test_push_with_big_meta
|
244
|
+
WebMock.enable_net_connect!
|
245
|
+
skip('We are offline') unless we_are_online
|
200
246
|
req =
|
201
247
|
with_http_server(200, 'yes') do |baza|
|
202
248
|
baza.push(
|
@@ -213,6 +259,8 @@ class TestBazaRb < Minitest::Test
|
|
213
259
|
end
|
214
260
|
|
215
261
|
def test_push_compressed_content
|
262
|
+
WebMock.enable_net_connect!
|
263
|
+
skip('We are offline') unless we_are_online
|
216
264
|
req =
|
217
265
|
with_http_server(200, 'yes') do |baza|
|
218
266
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -224,6 +272,8 @@ class TestBazaRb < Minitest::Test
|
|
224
272
|
end
|
225
273
|
|
226
274
|
def test_push_compression_disabled
|
275
|
+
WebMock.enable_net_connect!
|
276
|
+
skip('We are offline') unless we_are_online
|
227
277
|
req =
|
228
278
|
with_http_server(200, 'yes', compress: false) do |baza|
|
229
279
|
baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
|
@@ -234,6 +284,7 @@ class TestBazaRb < Minitest::Test
|
|
234
284
|
|
235
285
|
def test_with_very_short_timeout
|
236
286
|
WebMock.enable_net_connect!
|
287
|
+
skip('We are offline') unless we_are_online
|
237
288
|
host = '127.0.0.1'
|
238
289
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
239
290
|
server = TCPServer.new(host, port)
|
@@ -247,10 +298,10 @@ class TestBazaRb < Minitest::Test
|
|
247
298
|
socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nabc"
|
248
299
|
socket.close
|
249
300
|
end
|
250
|
-
|
251
|
-
assert_raises do
|
301
|
+
assert_includes(
|
302
|
+
assert_raises(StandardError) do
|
252
303
|
BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
|
253
|
-
end.message
|
304
|
+
end.message, 'timed out in'
|
254
305
|
)
|
255
306
|
t.join
|
256
307
|
end
|
@@ -261,6 +312,7 @@ class TestBazaRb < Minitest::Test
|
|
261
312
|
def with_http_server(code, response, opts = {})
|
262
313
|
opts = { ssl: false, timeout: 1 }.merge(opts)
|
263
314
|
WebMock.enable_net_connect!
|
315
|
+
skip('We are offline') unless we_are_online
|
264
316
|
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
265
317
|
host = '127.0.0.1'
|
266
318
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
@@ -280,10 +332,10 @@ class TestBazaRb < Minitest::Test
|
|
280
332
|
end
|
281
333
|
|
282
334
|
def fake_name
|
283
|
-
"fake
|
335
|
+
"fake#{SecureRandom.hex(8)}"
|
284
336
|
end
|
285
337
|
|
286
338
|
def we_are_online
|
287
|
-
Net::Ping::External.new('8.8.8.8').ping?
|
339
|
+
@we_are_online ||= Net::Ping::External.new('8.8.8.8').ping?
|
288
340
|
end
|
289
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: []
|