baza.rb 0.0.13 → 0.1.0
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/Gemfile +2 -0
- data/Gemfile.lock +25 -16
- data/Rakefile +12 -1
- data/baza.rb.gemspec +1 -1
- data/lib/baza-rb/fake.rb +70 -19
- data/lib/baza-rb/version.rb +1 -1
- data/test/test__helper.rb +1 -0
- data/test/test_baza-rb.rb +1 -2
- data/test/test_fake.rb +20 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c49b2f9e56518856e9b940ced30762aef5b5fbe261664e7a706da01cd0f6863d
|
4
|
+
data.tar.gz: 05b2facb756676b39d9260ba98f9b40a8ed8298fee49fab796134f23b9533343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321b9183088c669b9a81c9526f8315a33c744897ee28bc5e82bc2e0e6145d3159e55e3777dc742c571aedef03e6101894d9089c0da5593a2e4554ab6b882646b
|
7
|
+
data.tar.gz: eb58d54e0ce574a1583fe4a4d2048ea7a78c806311076a7e86f4cf0012d7ea32e67f269ae7b72d42c70da9f7840de990e6e6027c031b6684e54a9172e67435e5
|
data/Gemfile
CHANGED
@@ -11,6 +11,8 @@ gem 'factbase', '>0', require: false
|
|
11
11
|
gem 'minitest', '~>5.25', require: false
|
12
12
|
gem 'minitest-reporters', '~>1.7', require: false
|
13
13
|
gem 'net-ping', '~>2.0', require: false
|
14
|
+
gem 'os', '>0', require: false
|
15
|
+
gem 'qbash', '>0', require: false
|
14
16
|
gem 'rake', '~>13.2', require: false
|
15
17
|
gem 'random-port', '>0', require: false
|
16
18
|
gem 'rubocop', '~>1.73', require: false
|
data/Gemfile.lock
CHANGED
@@ -35,14 +35,15 @@ GEM
|
|
35
35
|
tago (> 0)
|
36
36
|
ethon (0.16.0)
|
37
37
|
ffi (>= 1.15.0)
|
38
|
-
factbase (0.9.
|
39
|
-
backtrace (
|
40
|
-
decoor (
|
38
|
+
factbase (0.9.10)
|
39
|
+
backtrace (~> 0.4)
|
40
|
+
decoor (~> 0.0)
|
41
41
|
json (~> 2.7)
|
42
|
-
|
42
|
+
logger (~> 1.0)
|
43
|
+
loog (~> 0.6)
|
43
44
|
nokogiri (~> 1.10)
|
44
|
-
others (
|
45
|
-
tago (
|
45
|
+
others (~> 0.0)
|
46
|
+
tago (~> 0.0)
|
46
47
|
yaml (~> 0.3)
|
47
48
|
faraday (2.12.2)
|
48
49
|
faraday-net_http (>= 2.0, < 3.5)
|
@@ -54,7 +55,7 @@ GEM
|
|
54
55
|
multipart-post (~> 2.0)
|
55
56
|
faraday-net_http (3.4.0)
|
56
57
|
net-http (>= 0.5.0)
|
57
|
-
faraday-retry (2.
|
58
|
+
faraday-retry (2.3.0)
|
58
59
|
faraday (~> 2.0)
|
59
60
|
ffi (1.17.1-arm64-darwin)
|
60
61
|
ffi (1.17.1-x64-mingw-ucrt)
|
@@ -77,21 +78,27 @@ GEM
|
|
77
78
|
net-http (0.6.0)
|
78
79
|
uri
|
79
80
|
net-ping (2.0.8)
|
80
|
-
nokogiri (1.18.
|
81
|
+
nokogiri (1.18.7-arm64-darwin)
|
81
82
|
racc (~> 1.4)
|
82
|
-
nokogiri (1.18.
|
83
|
+
nokogiri (1.18.7-x64-mingw-ucrt)
|
83
84
|
racc (~> 1.4)
|
84
|
-
nokogiri (1.18.
|
85
|
+
nokogiri (1.18.7-x86_64-darwin)
|
85
86
|
racc (~> 1.4)
|
86
|
-
nokogiri (1.18.
|
87
|
+
nokogiri (1.18.7-x86_64-linux-gnu)
|
87
88
|
racc (~> 1.4)
|
89
|
+
os (1.1.4)
|
88
90
|
others (0.0.3)
|
89
91
|
parallel (1.26.3)
|
90
|
-
parser (3.3.7.
|
92
|
+
parser (3.3.7.4)
|
91
93
|
ast (~> 2.4.1)
|
92
94
|
racc
|
93
95
|
prism (1.4.0)
|
94
96
|
public_suffix (6.0.1)
|
97
|
+
qbash (0.4.0)
|
98
|
+
backtrace (> 0)
|
99
|
+
elapsed (> 0)
|
100
|
+
loog (> 0)
|
101
|
+
tago (> 0)
|
95
102
|
racc (1.8.1)
|
96
103
|
rainbow (3.1.1)
|
97
104
|
rake (13.2.1)
|
@@ -114,13 +121,13 @@ GEM
|
|
114
121
|
rubocop-ast (1.43.0)
|
115
122
|
parser (>= 3.3.7.2)
|
116
123
|
prism (~> 1.4)
|
117
|
-
rubocop-minitest (0.
|
124
|
+
rubocop-minitest (0.38.0)
|
118
125
|
lint_roller (~> 1.1)
|
119
|
-
rubocop (>= 1.
|
126
|
+
rubocop (>= 1.75.0, < 2.0)
|
120
127
|
rubocop-ast (>= 1.38.0, < 2.0)
|
121
|
-
rubocop-performance (1.
|
128
|
+
rubocop-performance (1.25.0)
|
122
129
|
lint_roller (~> 1.1)
|
123
|
-
rubocop (>= 1.
|
130
|
+
rubocop (>= 1.75.0, < 2.0)
|
124
131
|
rubocop-ast (>= 1.38.0, < 2.0)
|
125
132
|
rubocop-rake (0.7.1)
|
126
133
|
lint_roller (~> 1.1)
|
@@ -167,6 +174,8 @@ DEPENDENCIES
|
|
167
174
|
minitest (~> 5.25)
|
168
175
|
minitest-reporters (~> 1.7)
|
169
176
|
net-ping (~> 2.0)
|
177
|
+
os (> 0)
|
178
|
+
qbash (> 0)
|
170
179
|
rake (~> 13.2)
|
171
180
|
random-port (> 0)
|
172
181
|
rubocop (~> 1.73)
|
data/Rakefile
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
+
require 'os'
|
7
|
+
require 'qbash'
|
6
8
|
require 'rubygems'
|
7
9
|
require 'rake'
|
8
10
|
require 'rake/clean'
|
11
|
+
require 'shellwords'
|
9
12
|
|
10
13
|
def name
|
11
14
|
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
|
@@ -17,7 +20,7 @@ end
|
|
17
20
|
|
18
21
|
ENV['RACK_ENV'] = 'test'
|
19
22
|
|
20
|
-
task default: %i[clean test rubocop yard]
|
23
|
+
task default: %i[clean test picks rubocop yard]
|
21
24
|
|
22
25
|
require 'rake/testtask'
|
23
26
|
desc 'Run all unit tests'
|
@@ -29,6 +32,14 @@ Rake::TestTask.new(:test) do |test|
|
|
29
32
|
test.verbose = false
|
30
33
|
end
|
31
34
|
|
35
|
+
desc 'Run them via Ruby, one by one'
|
36
|
+
task :picks do
|
37
|
+
next if OS.windows?
|
38
|
+
(Dir['test/**/*.rb'] + Dir['lib/**/*.rb']).each do |f|
|
39
|
+
qbash("bundle exec ruby #{Shellwords.escape(f)}", log: $stdout, env: { 'RACK_ENV' => 'picks' })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
32
43
|
require 'yard'
|
33
44
|
desc 'Build Yard documentation'
|
34
45
|
YARD::Rake::YardocTask.new do |t|
|
data/baza.rb.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
'and do everything else that is possible to do via the HTTP API.'
|
20
20
|
s.authors = ['Yegor Bugayenko']
|
21
21
|
s.email = 'yegor256@gmail.com'
|
22
|
-
s.homepage = '
|
22
|
+
s.homepage = 'https://github.com/zerocracy/baza.rb'
|
23
23
|
s.files = `git ls-files`.split($RS)
|
24
24
|
s.rdoc_options = ['--charset=UTF-8']
|
25
25
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
data/lib/baza-rb/fake.rb
CHANGED
@@ -22,7 +22,10 @@ class BazaRb::Fake
|
|
22
22
|
# @param [Bytes] data The data to push to the server (binary)
|
23
23
|
# @param [Array<String>] meta List of metas, possibly empty
|
24
24
|
# @return [Integer] Job ID on the server
|
25
|
-
def push(
|
25
|
+
def push(name, data, meta)
|
26
|
+
assert_name(name)
|
27
|
+
raise 'The data must be non-empty' if data.empty?
|
28
|
+
raise 'The meta must be an array' unless meta.is_a?(Array)
|
26
29
|
42
|
27
30
|
end
|
28
31
|
|
@@ -30,7 +33,8 @@ class BazaRb::Fake
|
|
30
33
|
#
|
31
34
|
# @param [Integer] id The ID of the job on the server
|
32
35
|
# @return [Bytes] Binary data pulled
|
33
|
-
def pull(
|
36
|
+
def pull(id)
|
37
|
+
assert_id(id)
|
34
38
|
Factbase.new.export
|
35
39
|
end
|
36
40
|
|
@@ -38,7 +42,8 @@ class BazaRb::Fake
|
|
38
42
|
#
|
39
43
|
# @param [Integer] id The ID of the job on the server
|
40
44
|
# @return [Boolean] TRUE if the job is already finished
|
41
|
-
def finished?(
|
45
|
+
def finished?(id)
|
46
|
+
assert_id(id)
|
42
47
|
true
|
43
48
|
end
|
44
49
|
|
@@ -46,7 +51,8 @@ class BazaRb::Fake
|
|
46
51
|
#
|
47
52
|
# @param [Integer] id The ID of the job on the server
|
48
53
|
# @return [String] The stdout, as a text
|
49
|
-
def stdout(
|
54
|
+
def stdout(id)
|
55
|
+
assert_id(id)
|
50
56
|
'Fake stdout output'
|
51
57
|
end
|
52
58
|
|
@@ -54,7 +60,8 @@ class BazaRb::Fake
|
|
54
60
|
#
|
55
61
|
# @param [Integer] id The ID of the job on the server
|
56
62
|
# @return [Integer] The exit code
|
57
|
-
def exit_code(
|
63
|
+
def exit_code(id)
|
64
|
+
assert_id(id)
|
58
65
|
0
|
59
66
|
end
|
60
67
|
|
@@ -62,7 +69,8 @@ class BazaRb::Fake
|
|
62
69
|
#
|
63
70
|
# @param [Integer] id The ID of the job on the server
|
64
71
|
# @return [String] The verdict
|
65
|
-
def verified(
|
72
|
+
def verified(id)
|
73
|
+
assert_id(id)
|
66
74
|
'fake-verdict'
|
67
75
|
end
|
68
76
|
|
@@ -71,7 +79,8 @@ class BazaRb::Fake
|
|
71
79
|
# @param [String] name The name of the job on the server
|
72
80
|
# @param [String] owner The owner of the lock (any string)
|
73
81
|
def lock(name, owner)
|
74
|
-
|
82
|
+
assert_name(name)
|
83
|
+
assert_owner(owner)
|
75
84
|
end
|
76
85
|
|
77
86
|
# Unlock the name.
|
@@ -79,14 +88,16 @@ class BazaRb::Fake
|
|
79
88
|
# @param [String] name The name of the job on the server
|
80
89
|
# @param [String] owner The owner of the lock (any string)
|
81
90
|
def unlock(name, owner)
|
82
|
-
|
91
|
+
assert_name(name)
|
92
|
+
assert_owner(owner)
|
83
93
|
end
|
84
94
|
|
85
95
|
# Get the ID of the job by the name.
|
86
96
|
#
|
87
97
|
# @param [String] name The name of the job on the server
|
88
98
|
# @return [Integer] The ID of the job on the server
|
89
|
-
def recent(
|
99
|
+
def recent(name)
|
100
|
+
assert_name(name)
|
90
101
|
42
|
91
102
|
end
|
92
103
|
|
@@ -94,7 +105,8 @@ class BazaRb::Fake
|
|
94
105
|
#
|
95
106
|
# @param [String] name The name of the job on the server
|
96
107
|
# @return [Boolean] TRUE if such name exists
|
97
|
-
def name_exists?(
|
108
|
+
def name_exists?(name)
|
109
|
+
assert_name(name)
|
98
110
|
true
|
99
111
|
end
|
100
112
|
|
@@ -103,7 +115,8 @@ class BazaRb::Fake
|
|
103
115
|
# @param [String] jname The name of the job on the server
|
104
116
|
# @param [String] file The file name
|
105
117
|
def durable_place(jname, file)
|
106
|
-
|
118
|
+
assert_name(jname)
|
119
|
+
assert_file(file)
|
107
120
|
end
|
108
121
|
|
109
122
|
# Save a single durable from local file to server.
|
@@ -111,7 +124,8 @@ class BazaRb::Fake
|
|
111
124
|
# @param [Integer] id The ID of the durable
|
112
125
|
# @param [String] file The file to upload
|
113
126
|
def durable_save(id, file)
|
114
|
-
|
127
|
+
assert_id(id)
|
128
|
+
assert_file(file)
|
115
129
|
end
|
116
130
|
|
117
131
|
# Load a single durable from server to local file.
|
@@ -119,7 +133,8 @@ class BazaRb::Fake
|
|
119
133
|
# @param [Integer] id The ID of the durable
|
120
134
|
# @param [String] file The file to upload
|
121
135
|
def durable_load(id, file)
|
122
|
-
|
136
|
+
assert_id(id)
|
137
|
+
assert_file(file)
|
123
138
|
end
|
124
139
|
|
125
140
|
# Lock a single durable.
|
@@ -127,7 +142,8 @@ class BazaRb::Fake
|
|
127
142
|
# @param [Integer] id The ID of the durable
|
128
143
|
# @param [String] owner The owner of the lock
|
129
144
|
def durable_lock(id, owner)
|
130
|
-
|
145
|
+
assert_id(id)
|
146
|
+
assert_owner(owner)
|
131
147
|
end
|
132
148
|
|
133
149
|
# Unlock a single durable.
|
@@ -135,7 +151,8 @@ class BazaRb::Fake
|
|
135
151
|
# @param [Integer] id The ID of the durable
|
136
152
|
# @param [String] owner The owner of the lock
|
137
153
|
def durable_unlock(id, owner)
|
138
|
-
|
154
|
+
assert_id(id)
|
155
|
+
assert_owner(owner)
|
139
156
|
end
|
140
157
|
|
141
158
|
# Transfer some funds to another user.
|
@@ -143,7 +160,11 @@ class BazaRb::Fake
|
|
143
160
|
# @param [String] recipient GitHub name (e.g. "yegor256") of the recipient
|
144
161
|
# @param [Float] amount The amount in Z/USDT (not zents!)
|
145
162
|
# @param [String] summary The description of the payment
|
146
|
-
def transfer(
|
163
|
+
def transfer(recipient, amount, summary, *)
|
164
|
+
raise "The receipient #{recipient.inspect} is not valid" unless recipient.match?(/^[a-zA-Z0-9-]+$/)
|
165
|
+
raise "The amount #{amount} must be a Float" unless amount.is_a?(Float)
|
166
|
+
raise "The amount #{amount} must be positive" unless amount.positive?
|
167
|
+
raise "The summary #{summary.inspect} is empty" if summary.empty?
|
147
168
|
42
|
148
169
|
end
|
149
170
|
|
@@ -152,7 +173,10 @@ class BazaRb::Fake
|
|
152
173
|
# @param [String] owner Who is acting (could be any text)
|
153
174
|
# @param [String] zip The path to ZIP archive to take
|
154
175
|
# @return [Boolean] TRUE if job taken, otherwise false
|
155
|
-
def pop(
|
176
|
+
def pop(owner, zip)
|
177
|
+
assert_owner(owner)
|
178
|
+
FileUtils.mkdir_p(File.dirname(zip))
|
179
|
+
FileUtils.touch(zip)
|
156
180
|
true
|
157
181
|
end
|
158
182
|
|
@@ -161,7 +185,8 @@ class BazaRb::Fake
|
|
161
185
|
# @param [Integer] id The ID of the job on the server
|
162
186
|
# @param [String] zip The path to the ZIP file with the content of the archive
|
163
187
|
def finish(id, zip)
|
164
|
-
|
188
|
+
assert_id(id)
|
189
|
+
assert_file(zip)
|
165
190
|
end
|
166
191
|
|
167
192
|
# Enter a valve.
|
@@ -171,7 +196,11 @@ class BazaRb::Fake
|
|
171
196
|
# @param [String] why The reason
|
172
197
|
# @param [nil|Integer] job The ID of the job
|
173
198
|
# @return [String] The result just calculated or retrieved
|
174
|
-
def enter(
|
199
|
+
def enter(name, badge, why, job)
|
200
|
+
assert_name(name)
|
201
|
+
raise "The badge '#{badge}' is not valid" unless badge.match?(/^[a-zA-Z0-9_-]+$/)
|
202
|
+
raise 'The reason cannot be empty' if why.empty?
|
203
|
+
assert_id(job) unless job.nil?
|
175
204
|
yield
|
176
205
|
end
|
177
206
|
|
@@ -180,4 +209,26 @@ class BazaRb::Fake
|
|
180
209
|
def csrf
|
181
210
|
'fake-csrf-token'
|
182
211
|
end
|
212
|
+
|
213
|
+
private
|
214
|
+
|
215
|
+
def assert_name(name)
|
216
|
+
raise "The name #{name.inspect} is not valid" unless name.match?(/^[a-z0-9-]+$/)
|
217
|
+
raise "The name #{name.inspect} is too long" if name.length > 32
|
218
|
+
end
|
219
|
+
|
220
|
+
def assert_id(id)
|
221
|
+
raise 'The ID must be an Integer' unless id.is_a?(Integer)
|
222
|
+
raise 'The ID must be positive' unless id.positive?
|
223
|
+
end
|
224
|
+
|
225
|
+
def assert_owner(owner)
|
226
|
+
raise "The owner #{owner.inspect} is not valid" unless owner.match?(/^[a-zA-Z0-9-]+$/)
|
227
|
+
raise "The owner #{owner.inspect} is too long" if owner.length > 64
|
228
|
+
end
|
229
|
+
|
230
|
+
def assert_file(file)
|
231
|
+
raise 'The file must exist' unless File.exist?(file)
|
232
|
+
raise 'The file must be non-empty' unless File.size(file).positive?
|
233
|
+
end
|
183
234
|
end
|
data/lib/baza-rb/version.rb
CHANGED
data/test/test__helper.rb
CHANGED
data/test/test_baza-rb.rb
CHANGED
@@ -5,15 +5,14 @@
|
|
5
5
|
|
6
6
|
require 'factbase'
|
7
7
|
require 'loog'
|
8
|
-
require 'minitest/autorun'
|
9
8
|
require 'net/ping'
|
10
9
|
require 'random-port'
|
11
10
|
require 'securerandom'
|
12
11
|
require 'socket'
|
13
12
|
require 'stringio'
|
14
13
|
require 'wait_for'
|
15
|
-
require 'webmock/minitest'
|
16
14
|
require 'webrick'
|
15
|
+
require_relative 'test__helper'
|
17
16
|
require_relative '../lib/baza-rb'
|
18
17
|
|
19
18
|
# Test.
|
data/test/test_fake.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
+
require_relative 'test__helper'
|
6
7
|
require_relative '../lib/baza-rb/fake'
|
7
8
|
|
8
9
|
# Test fake object.
|
@@ -64,11 +65,15 @@ class TestFake < Minitest::Test
|
|
64
65
|
|
65
66
|
def test_durable_operations
|
66
67
|
baza = BazaRb::Fake.new
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
Dir.mktmpdir do |tmp|
|
69
|
+
f = File.join(tmp, 'test.bin')
|
70
|
+
File.write(f, 'hello')
|
71
|
+
baza.durable_place('test-job', f)
|
72
|
+
baza.durable_save(42, f)
|
73
|
+
baza.durable_load(42, f)
|
74
|
+
baza.durable_lock(42, 'test-owner')
|
75
|
+
baza.durable_unlock(42, 'test-owner')
|
76
|
+
end
|
72
77
|
end
|
73
78
|
|
74
79
|
def test_transfer
|
@@ -79,13 +84,20 @@ class TestFake < Minitest::Test
|
|
79
84
|
|
80
85
|
def test_pop
|
81
86
|
baza = BazaRb::Fake.new
|
82
|
-
|
83
|
-
|
87
|
+
Dir.mktmpdir do |tmp|
|
88
|
+
f = File.join(tmp, 'test.zip')
|
89
|
+
result = baza.pop('test-owner', f)
|
90
|
+
assert(result)
|
91
|
+
end
|
84
92
|
end
|
85
93
|
|
86
94
|
def test_finish
|
87
95
|
baza = BazaRb::Fake.new
|
88
|
-
|
96
|
+
Dir.mktmpdir do |tmp|
|
97
|
+
f = File.join(tmp, 'test.zip')
|
98
|
+
File.write(f, 'hello')
|
99
|
+
baza.finish(42, f)
|
100
|
+
end
|
89
101
|
end
|
90
102
|
|
91
103
|
def test_enter
|
metadata
CHANGED
@@ -1,13 +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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: backtrace
|
@@ -205,7 +205,7 @@ files:
|
|
205
205
|
- test/test__helper.rb
|
206
206
|
- test/test_baza-rb.rb
|
207
207
|
- test/test_fake.rb
|
208
|
-
homepage:
|
208
|
+
homepage: https://github.com/zerocracy/baza.rb
|
209
209
|
licenses:
|
210
210
|
- MIT
|
211
211
|
metadata:
|