baza.rb 0.0.11 → 0.0.12
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/lib/baza-rb/fake.rb +183 -0
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +1 -0
- data/test/test_fake.rb +105 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2879a58b22740c55d8f4f433ad17d903c1d60fb4ffb7474f3e38eafd4de34c70
|
4
|
+
data.tar.gz: 2a37091f3541e6d44bf132532a0f77b3d813dbfad4e3a2b2d602419d5e48be43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d10abffe172d128c5cf4b0e15db6e24236378d4a13e8ce0ce4d303807c949196ac00b90daae47993250fc6f4c4ae4c58472160fdd51ff0665975a850bff18117
|
7
|
+
data.tar.gz: 634cf07d3c82b9685f46ced49044cf68c1f19c4a3e58a7e131a50e8f3d146cb33cc2011f641500b4c6ea2c930f0f896b624e347381845719b326390e33f238c8
|
data/lib/baza-rb/fake.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
require 'factbase'
|
7
|
+
require_relative '../baza-rb'
|
8
|
+
require_relative 'version'
|
9
|
+
|
10
|
+
# Fake interface to the API of zerocracy.com for testing.
|
11
|
+
#
|
12
|
+
# This class implements the same public interface as BazaRb but doesn't
|
13
|
+
# make any network connections, instead returning predefined fake values.
|
14
|
+
#
|
15
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
16
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
17
|
+
# License:: MIT
|
18
|
+
class BazaRb::Fake
|
19
|
+
# Push factbase to the server.
|
20
|
+
#
|
21
|
+
# @param [String] name The name of the job on the server
|
22
|
+
# @param [Bytes] data The data to push to the server (binary)
|
23
|
+
# @param [Array<String>] meta List of metas, possibly empty
|
24
|
+
# @return [Integer] Job ID on the server
|
25
|
+
def push(_name, _data, _meta)
|
26
|
+
42
|
27
|
+
end
|
28
|
+
|
29
|
+
# Pull factbase from the server.
|
30
|
+
#
|
31
|
+
# @param [Integer] id The ID of the job on the server
|
32
|
+
# @return [Bytes] Binary data pulled
|
33
|
+
def pull(_id)
|
34
|
+
Factbase.new.export
|
35
|
+
end
|
36
|
+
|
37
|
+
# The job with this ID is finished already?
|
38
|
+
#
|
39
|
+
# @param [Integer] id The ID of the job on the server
|
40
|
+
# @return [Boolean] TRUE if the job is already finished
|
41
|
+
def finished?(_id)
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
# Read and return the stdout of the job.
|
46
|
+
#
|
47
|
+
# @param [Integer] id The ID of the job on the server
|
48
|
+
# @return [String] The stdout, as a text
|
49
|
+
def stdout(_id)
|
50
|
+
'Fake stdout output'
|
51
|
+
end
|
52
|
+
|
53
|
+
# Read and return the exit code of the job.
|
54
|
+
#
|
55
|
+
# @param [Integer] id The ID of the job on the server
|
56
|
+
# @return [Integer] The exit code
|
57
|
+
def exit_code(_id)
|
58
|
+
0
|
59
|
+
end
|
60
|
+
|
61
|
+
# Read and return the verification verdict of the job.
|
62
|
+
#
|
63
|
+
# @param [Integer] id The ID of the job on the server
|
64
|
+
# @return [String] The verdict
|
65
|
+
def verified(_id)
|
66
|
+
'fake-verdict'
|
67
|
+
end
|
68
|
+
|
69
|
+
# Lock the name.
|
70
|
+
#
|
71
|
+
# @param [String] name The name of the job on the server
|
72
|
+
# @param [String] owner The owner of the lock (any string)
|
73
|
+
def lock(name, owner)
|
74
|
+
# nothing
|
75
|
+
end
|
76
|
+
|
77
|
+
# Unlock the name.
|
78
|
+
#
|
79
|
+
# @param [String] name The name of the job on the server
|
80
|
+
# @param [String] owner The owner of the lock (any string)
|
81
|
+
def unlock(name, owner)
|
82
|
+
# nothing
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get the ID of the job by the name.
|
86
|
+
#
|
87
|
+
# @param [String] name The name of the job on the server
|
88
|
+
# @return [Integer] The ID of the job on the server
|
89
|
+
def recent(_name)
|
90
|
+
42
|
91
|
+
end
|
92
|
+
|
93
|
+
# Check whether the name of the job exists on the server.
|
94
|
+
#
|
95
|
+
# @param [String] name The name of the job on the server
|
96
|
+
# @return [Boolean] TRUE if such name exists
|
97
|
+
def name_exists?(_name)
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
# Place a single durable.
|
102
|
+
#
|
103
|
+
# @param [String] jname The name of the job on the server
|
104
|
+
# @param [String] file The file name
|
105
|
+
def durable_place(jname, file)
|
106
|
+
# nothing
|
107
|
+
end
|
108
|
+
|
109
|
+
# Save a single durable from local file to server.
|
110
|
+
#
|
111
|
+
# @param [Integer] id The ID of the durable
|
112
|
+
# @param [String] file The file to upload
|
113
|
+
def durable_save(id, file)
|
114
|
+
# nothing
|
115
|
+
end
|
116
|
+
|
117
|
+
# Load a single durable from server to local file.
|
118
|
+
#
|
119
|
+
# @param [Integer] id The ID of the durable
|
120
|
+
# @param [String] file The file to upload
|
121
|
+
def durable_load(id, file)
|
122
|
+
# nothing
|
123
|
+
end
|
124
|
+
|
125
|
+
# Lock a single durable.
|
126
|
+
#
|
127
|
+
# @param [Integer] id The ID of the durable
|
128
|
+
# @param [String] owner The owner of the lock
|
129
|
+
def durable_lock(id, owner)
|
130
|
+
# nothing
|
131
|
+
end
|
132
|
+
|
133
|
+
# Unlock a single durable.
|
134
|
+
#
|
135
|
+
# @param [Integer] id The ID of the durable
|
136
|
+
# @param [String] owner The owner of the lock
|
137
|
+
def durable_unlock(id, owner)
|
138
|
+
# nothing
|
139
|
+
end
|
140
|
+
|
141
|
+
# Transfer some funds to another user.
|
142
|
+
#
|
143
|
+
# @param [String] recipient GitHub name (e.g. "yegor256") of the recipient
|
144
|
+
# @param [Float] amount The amount in Z/USDT (not zents!)
|
145
|
+
# @param [String] summary The description of the payment
|
146
|
+
def transfer(_recipient, _amount, _summary)
|
147
|
+
42
|
148
|
+
end
|
149
|
+
|
150
|
+
# Pop job from the server.
|
151
|
+
#
|
152
|
+
# @param [String] owner Who is acting (could be any text)
|
153
|
+
# @param [String] zip The path to ZIP archive to take
|
154
|
+
# @return [Boolean] TRUE if job taken, otherwise false
|
155
|
+
def pop(_owner, _zip)
|
156
|
+
true
|
157
|
+
end
|
158
|
+
|
159
|
+
# Submit a ZIP archive to finish a job.
|
160
|
+
#
|
161
|
+
# @param [Integer] id The ID of the job on the server
|
162
|
+
# @param [String] zip The path to the ZIP file with the content of the archive
|
163
|
+
def finish(id, zip)
|
164
|
+
# nothing
|
165
|
+
end
|
166
|
+
|
167
|
+
# Enter a valve.
|
168
|
+
#
|
169
|
+
# @param [String] name Name of the job
|
170
|
+
# @param [String] badge Unique badge of the valve
|
171
|
+
# @param [String] why The reason
|
172
|
+
# @param [nil|Integer] job The ID of the job
|
173
|
+
# @return [String] The result just calculated or retrieved
|
174
|
+
def enter(_name, _badge, _why, _job)
|
175
|
+
yield
|
176
|
+
end
|
177
|
+
|
178
|
+
# Get CSRF token from the server.
|
179
|
+
# @return [String] The token for this user
|
180
|
+
def csrf
|
181
|
+
'fake-csrf-token'
|
182
|
+
end
|
183
|
+
end
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -466,6 +466,7 @@ class BazaRb
|
|
466
466
|
# @param [String] recipient GitHub name (e.g. "yegor256") of the recipient
|
467
467
|
# @param [Float] amount The amount in Z/USDT (not zents!)
|
468
468
|
# @param [String] summary The description of the payment
|
469
|
+
# @return [Integer] Receipt ID
|
469
470
|
def transfer(recipient, amount, summary)
|
470
471
|
raise 'The "recipient" is nil' if recipient.nil?
|
471
472
|
raise 'The "amount" is nil' if amount.nil?
|
data/test/test_fake.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
require_relative '../lib/baza-rb/fake'
|
7
|
+
|
8
|
+
# Test fake object.
|
9
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
10
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
11
|
+
# License:: MIT
|
12
|
+
class TestFake < Minitest::Test
|
13
|
+
def test_pull
|
14
|
+
baza = BazaRb::Fake.new
|
15
|
+
bin = baza.pull(42)
|
16
|
+
refute_nil(bin)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_push
|
20
|
+
baza = BazaRb::Fake.new
|
21
|
+
id = baza.push('test-job', 'test-data', [])
|
22
|
+
assert_equal(42, id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_finished
|
26
|
+
baza = BazaRb::Fake.new
|
27
|
+
assert(baza.finished?(42))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_stdout
|
31
|
+
baza = BazaRb::Fake.new
|
32
|
+
output = baza.stdout(42)
|
33
|
+
assert_equal('Fake stdout output', output)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_exit_code
|
37
|
+
baza = BazaRb::Fake.new
|
38
|
+
code = baza.exit_code(42)
|
39
|
+
assert_equal(0, code)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_verified
|
43
|
+
baza = BazaRb::Fake.new
|
44
|
+
verdict = baza.verified(42)
|
45
|
+
assert_equal('fake-verdict', verdict)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_lock_unlock
|
49
|
+
baza = BazaRb::Fake.new
|
50
|
+
baza.lock('test-job', 'test-owner')
|
51
|
+
baza.unlock('test-job', 'test-owner')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_recent
|
55
|
+
baza = BazaRb::Fake.new
|
56
|
+
id = baza.recent('test-job')
|
57
|
+
assert_equal(42, id)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_name_exists
|
61
|
+
baza = BazaRb::Fake.new
|
62
|
+
assert(baza.name_exists?('test-job'))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_durable_operations
|
66
|
+
baza = BazaRb::Fake.new
|
67
|
+
baza.durable_place('test-job', 'test-file')
|
68
|
+
baza.durable_save(42, 'test-file')
|
69
|
+
baza.durable_load(42, 'test-file')
|
70
|
+
baza.durable_lock(42, 'test-owner')
|
71
|
+
baza.durable_unlock(42, 'test-owner')
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_transfer
|
75
|
+
baza = BazaRb::Fake.new
|
76
|
+
receipt_id = baza.transfer('recipient', 1.0, 'test-payment')
|
77
|
+
assert_equal(42, receipt_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_pop
|
81
|
+
baza = BazaRb::Fake.new
|
82
|
+
result = baza.pop('test-owner', 'test.zip')
|
83
|
+
assert(result)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_finish
|
87
|
+
baza = BazaRb::Fake.new
|
88
|
+
baza.finish(42, 'test.zip')
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_enter
|
92
|
+
baza = BazaRb::Fake.new
|
93
|
+
result =
|
94
|
+
baza.enter('test-job', 'test-badge', 'test-reason', 42) do
|
95
|
+
'test-result'
|
96
|
+
end
|
97
|
+
assert_equal('test-result', result)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_csrf
|
101
|
+
baza = BazaRb::Fake.new
|
102
|
+
token = baza.csrf
|
103
|
+
assert_equal('fake-csrf-token', token)
|
104
|
+
end
|
105
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -199,10 +199,12 @@ files:
|
|
199
199
|
- Rakefile
|
200
200
|
- baza.rb.gemspec
|
201
201
|
- lib/baza-rb.rb
|
202
|
+
- lib/baza-rb/fake.rb
|
202
203
|
- lib/baza-rb/version.rb
|
203
204
|
- renovate.json
|
204
205
|
- test/test__helper.rb
|
205
206
|
- test/test_baza-rb.rb
|
207
|
+
- test/test_fake.rb
|
206
208
|
homepage: http://github.com/zerocracy/baza.rb
|
207
209
|
licenses:
|
208
210
|
- MIT
|