baza.rb 0.4.0 → 0.5.1
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/.github/workflows/copyrights.yml +1 -1
- data/.github/workflows/markdown-lint.yml +1 -1
- data/.github/workflows/rake.yml +1 -0
- data/.github/workflows/typos.yml +19 -0
- data/.gitignore +3 -2
- data/.rubocop.yml +1 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +27 -28
- data/README.md +1 -1
- data/REUSE.toml +7 -7
- data/Rakefile +10 -6
- data/baza.rb.gemspec +1 -1
- data/lib/baza-rb/fake.rb +49 -38
- data/lib/baza-rb/version.rb +2 -2
- data/lib/baza-rb.rb +162 -107
- data/test/test__helper.rb +20 -6
- data/test/test_baza-rb.rb +316 -32
- data/test/test_fake.rb +1 -1
- metadata +6 -5
data/test/test_baza-rb.rb
CHANGED
@@ -5,11 +5,12 @@
|
|
5
5
|
|
6
6
|
require 'factbase'
|
7
7
|
require 'loog'
|
8
|
-
require 'net/
|
8
|
+
require 'net/http'
|
9
9
|
require 'random-port'
|
10
10
|
require 'securerandom'
|
11
11
|
require 'socket'
|
12
12
|
require 'stringio'
|
13
|
+
require 'uri'
|
13
14
|
require 'wait_for'
|
14
15
|
require 'webrick'
|
15
16
|
require_relative 'test__helper'
|
@@ -17,10 +18,10 @@ require_relative '../lib/baza-rb'
|
|
17
18
|
|
18
19
|
# Test.
|
19
20
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
20
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
21
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
21
22
|
# License:: MIT
|
22
23
|
class TestBazaRb < Minitest::Test
|
23
|
-
# The token to use for testing:
|
24
|
+
# The token to use for testing, in Zerocracy.com:
|
24
25
|
TOKEN = '00000000-0000-0000-0000-000000000000'
|
25
26
|
|
26
27
|
# The host of the production platform:
|
@@ -32,7 +33,7 @@ class TestBazaRb < Minitest::Test
|
|
32
33
|
# Live agent:
|
33
34
|
LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::VERBOSE)
|
34
35
|
|
35
|
-
def
|
36
|
+
def test_live_full_cycle
|
36
37
|
WebMock.enable_net_connect!
|
37
38
|
skip('We are offline') unless we_are_online
|
38
39
|
fb = Factbase.new
|
@@ -43,7 +44,12 @@ class TestBazaRb < Minitest::Test
|
|
43
44
|
assert(LIVE.name_exists?(n))
|
44
45
|
assert_predicate(LIVE.recent(n), :positive?)
|
45
46
|
id = LIVE.recent(n)
|
46
|
-
|
47
|
+
assert(
|
48
|
+
wait_for(8 * 60) do
|
49
|
+
sleep(5)
|
50
|
+
LIVE.finished?(id)
|
51
|
+
end
|
52
|
+
)
|
47
53
|
refute_nil(LIVE.pull(id))
|
48
54
|
refute_nil(LIVE.stdout(id))
|
49
55
|
refute_nil(LIVE.exit_code(id))
|
@@ -120,7 +126,7 @@ class TestBazaRb < Minitest::Test
|
|
120
126
|
stub_request(:post, 'https://example.org/account/transfer').to_return(
|
121
127
|
status: 302, headers: { 'X-Zerocracy-ReceiptId' => '42' }
|
122
128
|
)
|
123
|
-
id =
|
129
|
+
id = fake_baza.transfer('jeff', 42.50, 'for fun')
|
124
130
|
assert_equal(42, id)
|
125
131
|
end
|
126
132
|
|
@@ -130,10 +136,40 @@ class TestBazaRb < Minitest::Test
|
|
130
136
|
stub_request(:post, 'https://example.org/account/transfer').to_return(
|
131
137
|
status: 302, headers: { 'X-Zerocracy-ReceiptId' => '42' }
|
132
138
|
)
|
133
|
-
id =
|
139
|
+
id = fake_baza.transfer('jeff', 42.50, 'for fun', job: 555)
|
134
140
|
assert_equal(42, id)
|
135
141
|
end
|
136
142
|
|
143
|
+
def test_reads_whoami
|
144
|
+
WebMock.disable_net_connect!
|
145
|
+
stub_request(:get, 'https://example.org/whoami').to_return(status: 200, body: 'jeff')
|
146
|
+
assert_equal('jeff', fake_baza.whoami)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_reads_balance
|
150
|
+
WebMock.disable_net_connect!
|
151
|
+
stub_request(:get, 'https://example.org/account/balance').to_return(status: 200, body: '42.33')
|
152
|
+
assert_in_delta(42.33, fake_baza.balance)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_checks_whether_job_is_finished
|
156
|
+
WebMock.disable_net_connect!
|
157
|
+
stub_request(:get, 'https://example.org/finished/42').to_return(status: 200, body: 'yes')
|
158
|
+
assert(fake_baza.finished?(42))
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_reads_verification_verdict
|
162
|
+
WebMock.disable_net_connect!
|
163
|
+
stub_request(:get, 'https://example.org/jobs/42/verified.txt').to_return(status: 200, body: 'done')
|
164
|
+
assert(fake_baza.verified(42))
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_unlocks_job_by_name
|
168
|
+
WebMock.disable_net_connect!
|
169
|
+
stub_request(:get, 'https://example.org/unlock/foo?owner=x').to_return(status: 302)
|
170
|
+
assert(fake_baza.unlock('foo', 'x'))
|
171
|
+
end
|
172
|
+
|
137
173
|
def test_durable_place
|
138
174
|
WebMock.disable_net_connect!
|
139
175
|
stub_request(:get, 'https://example.org/csrf').to_return(body: 'token')
|
@@ -143,7 +179,7 @@ class TestBazaRb < Minitest::Test
|
|
143
179
|
Dir.mktmpdir do |dir|
|
144
180
|
file = File.join(dir, 'test.bin')
|
145
181
|
File.binwrite(file, 'hello')
|
146
|
-
assert_equal(42,
|
182
|
+
assert_equal(42, fake_baza.durable_place('simple', file))
|
147
183
|
end
|
148
184
|
end
|
149
185
|
|
@@ -154,24 +190,71 @@ class TestBazaRb < Minitest::Test
|
|
154
190
|
)
|
155
191
|
assert_equal(
|
156
192
|
42,
|
157
|
-
|
193
|
+
fake_baza.push('simple', 'hello, world!', [])
|
158
194
|
)
|
159
195
|
end
|
160
196
|
|
161
|
-
def
|
197
|
+
def test_simple_pop_with_no_job_found
|
162
198
|
WebMock.disable_net_connect!
|
163
199
|
stub_request(:get, 'https://example.org/pop?owner=me').to_return(status: 204)
|
164
200
|
Tempfile.open do |zip|
|
165
|
-
refute(
|
201
|
+
refute(fake_baza.pop('me', zip.path))
|
166
202
|
refute_path_exists(zip.path)
|
167
203
|
end
|
168
204
|
end
|
169
205
|
|
206
|
+
def test_simple_pop_with_ranges
|
207
|
+
WebMock.disable_net_connect!
|
208
|
+
owner = 'owner888'
|
209
|
+
job = 4242
|
210
|
+
stub_request(:get, 'https://example.org/pop')
|
211
|
+
.with(query: { owner: })
|
212
|
+
.to_return(
|
213
|
+
status: 206,
|
214
|
+
headers: { 'Content-Range' => 'bytes 0-0/*', 'X-Zerocracy-JobId' => job, 'Content-Length' => 0 },
|
215
|
+
body: ''
|
216
|
+
)
|
217
|
+
bin = nil
|
218
|
+
Tempfile.open do |zip|
|
219
|
+
File.binwrite(zip.path, 'the archive to return (not a real ZIP for now)')
|
220
|
+
bin = File.binread(zip.path)
|
221
|
+
stub_request(:get, 'https://example.org/pop')
|
222
|
+
.with(query: { job:, owner: })
|
223
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
224
|
+
.to_return(
|
225
|
+
status: 206,
|
226
|
+
headers: {
|
227
|
+
'Content-Range' => "bytes 0-7/#{bin.size}",
|
228
|
+
'X-Zerocracy-JobId' => job,
|
229
|
+
'Content-Length' => 8
|
230
|
+
},
|
231
|
+
body: bin[0..7]
|
232
|
+
)
|
233
|
+
stub_request(:get, 'https://example.org/pop')
|
234
|
+
.with(query: { job:, owner: })
|
235
|
+
.with(headers: { 'Range' => 'bytes=8-' })
|
236
|
+
.to_return(
|
237
|
+
status: 206,
|
238
|
+
headers: {
|
239
|
+
'Content-Range' => "bytes 8-#{bin.size - 1}/#{bin.size}",
|
240
|
+
'X-Zerocracy-JobId' => job,
|
241
|
+
'Content-Length' => bin.size - 8
|
242
|
+
},
|
243
|
+
body: bin[8..]
|
244
|
+
)
|
245
|
+
end
|
246
|
+
Tempfile.open do |zip|
|
247
|
+
assert(fake_baza.pop(owner, zip.path))
|
248
|
+
assert_path_exists(zip.path)
|
249
|
+
assert_equal(bin, File.binread(zip.path))
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
170
253
|
def test_simple_finish
|
171
254
|
WebMock.disable_net_connect!
|
172
255
|
stub_request(:put, 'https://example.org/finish?id=42').to_return(status: 200)
|
173
256
|
Tempfile.open do |zip|
|
174
|
-
|
257
|
+
fake_baza.finish(42, zip.path)
|
175
258
|
end
|
176
259
|
end
|
177
260
|
|
@@ -182,7 +265,7 @@ class TestBazaRb < Minitest::Test
|
|
182
265
|
.to_return(status: 200, body: '42')
|
183
266
|
assert_equal(
|
184
267
|
42,
|
185
|
-
|
268
|
+
fake_baza.recent('simple')
|
186
269
|
)
|
187
270
|
end
|
188
271
|
|
@@ -192,7 +275,7 @@ class TestBazaRb < Minitest::Test
|
|
192
275
|
status: 200, body: 'yes'
|
193
276
|
)
|
194
277
|
assert(
|
195
|
-
|
278
|
+
fake_baza.name_exists?('simple')
|
196
279
|
)
|
197
280
|
end
|
198
281
|
|
@@ -202,7 +285,7 @@ class TestBazaRb < Minitest::Test
|
|
202
285
|
status: 200, body: '0'
|
203
286
|
)
|
204
287
|
assert_predicate(
|
205
|
-
|
288
|
+
fake_baza.exit_code(42), :zero?
|
206
289
|
)
|
207
290
|
end
|
208
291
|
|
@@ -212,7 +295,7 @@ class TestBazaRb < Minitest::Test
|
|
212
295
|
status: 200, body: 'hello!'
|
213
296
|
)
|
214
297
|
refute_empty(
|
215
|
-
|
298
|
+
fake_baza.stdout(42)
|
216
299
|
)
|
217
300
|
end
|
218
301
|
|
@@ -222,21 +305,21 @@ class TestBazaRb < Minitest::Test
|
|
222
305
|
status: 200, body: 'hello, world!'
|
223
306
|
)
|
224
307
|
assert(
|
225
|
-
|
308
|
+
fake_baza.pull(333).start_with?('hello')
|
226
309
|
)
|
227
310
|
end
|
228
311
|
|
229
312
|
def test_simple_lock_success
|
230
313
|
WebMock.disable_net_connect!
|
231
314
|
stub_request(:get, 'https://example.org/lock/name?owner=owner').to_return(status: 302)
|
232
|
-
|
315
|
+
fake_baza.lock('name', 'owner')
|
233
316
|
end
|
234
317
|
|
235
318
|
def test_simple_lock_failure
|
236
319
|
WebMock.disable_net_connect!
|
237
320
|
stub_request(:get, 'https://example.org/lock/name?owner=owner').to_return(status: 409)
|
238
321
|
assert_raises(StandardError) do
|
239
|
-
|
322
|
+
fake_baza.lock('name', 'owner')
|
240
323
|
end
|
241
324
|
end
|
242
325
|
|
@@ -245,7 +328,7 @@ class TestBazaRb < Minitest::Test
|
|
245
328
|
stub_request(:put, 'https://example.org/push/foo')
|
246
329
|
.to_return(status: 503, body: 'oops', headers: { 'X-Zerocracy-Failure': 'the failure' })
|
247
330
|
.to_raise('why second time?')
|
248
|
-
e = assert_raises(StandardError) {
|
331
|
+
e = assert_raises(StandardError) { fake_baza.push('foo', 'data', []) }
|
249
332
|
[
|
250
333
|
'Invalid response code #503',
|
251
334
|
'"the failure"'
|
@@ -293,30 +376,32 @@ class TestBazaRb < Minitest::Test
|
|
293
376
|
def test_push_compressed_content
|
294
377
|
WebMock.enable_net_connect!
|
295
378
|
skip('We are offline') unless we_are_online
|
379
|
+
fb = Factbase.new
|
380
|
+
fb.insert.foo = 'test-' * 10_000
|
296
381
|
req =
|
297
382
|
with_http_server(200, 'yes') do |baza|
|
298
|
-
baza.push('simple',
|
383
|
+
baza.push('simple', fb.export, %w[meta1 meta2 meta3])
|
299
384
|
end
|
300
385
|
assert_equal('application/zip', req.content_type)
|
301
386
|
assert_equal('gzip', req['content-encoding'])
|
302
387
|
body = Zlib::GzipReader.zcat(StringIO.new(req.body))
|
303
|
-
assert_equal(
|
388
|
+
assert_equal(fb.export, body)
|
304
389
|
end
|
305
390
|
|
306
391
|
def test_push_compression_disabled
|
307
392
|
WebMock.enable_net_connect!
|
308
|
-
|
393
|
+
fb = Factbase.new
|
394
|
+
fb.insert.foo = 'test-' * 10_000
|
309
395
|
req =
|
310
396
|
with_http_server(200, 'yes', compress: false) do |baza|
|
311
|
-
baza.push('simple',
|
397
|
+
baza.push('simple', fb.export, %w[meta1 meta2 meta3])
|
312
398
|
end
|
313
399
|
assert_equal('application/octet-stream', req.content_type)
|
314
|
-
assert_equal(
|
400
|
+
assert_equal(fb.export, req.body)
|
315
401
|
end
|
316
402
|
|
317
403
|
def test_with_very_short_timeout
|
318
404
|
WebMock.enable_net_connect!
|
319
|
-
skip('We are offline') unless we_are_online
|
320
405
|
host = '127.0.0.1'
|
321
406
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
322
407
|
server = TCPServer.new(host, port)
|
@@ -335,16 +420,192 @@ class TestBazaRb < Minitest::Test
|
|
335
420
|
BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
|
336
421
|
end.message, 'timed out in'
|
337
422
|
)
|
338
|
-
t.
|
423
|
+
t.terminate
|
424
|
+
assert(t.join(1))
|
339
425
|
end
|
340
426
|
end
|
341
427
|
|
428
|
+
def test_durable_save
|
429
|
+
WebMock.disable_net_connect!
|
430
|
+
Dir.mktmpdir do |dir|
|
431
|
+
file = File.join(dir, 'test.txt')
|
432
|
+
File.write(file, 'test content')
|
433
|
+
stub_request(:put, 'https://example.org:443/durables/42')
|
434
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' }, body: 'test content')
|
435
|
+
.to_return(status: 200)
|
436
|
+
fake_baza.durable_save(42, file)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_durable_load
|
441
|
+
WebMock.disable_net_connect!
|
442
|
+
Dir.mktmpdir do |dir|
|
443
|
+
file = File.join(dir, 'loaded.txt')
|
444
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
445
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
446
|
+
.to_return(status: 200, body: 'loaded content')
|
447
|
+
fake_baza.durable_load(42, file)
|
448
|
+
assert_equal('loaded content', File.read(file))
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
def test_durable_lock
|
453
|
+
WebMock.disable_net_connect!
|
454
|
+
stub_request(:get, 'https://example.org:443/durables/42/lock?owner=test-owner')
|
455
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
456
|
+
.to_return(status: 302)
|
457
|
+
fake_baza.durable_lock(42, 'test-owner')
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_durable_unlock
|
461
|
+
WebMock.disable_net_connect!
|
462
|
+
stub_request(:get, 'https://example.org:443/durables/42/unlock?owner=test-owner')
|
463
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
464
|
+
.to_return(status: 302)
|
465
|
+
fake_baza.durable_unlock(42, 'test-owner')
|
466
|
+
end
|
467
|
+
|
468
|
+
def test_fee
|
469
|
+
WebMock.disable_net_connect!
|
470
|
+
stub_request(:get, 'https://example.org:443/csrf')
|
471
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
472
|
+
.to_return(status: 200, body: 'csrf-token')
|
473
|
+
stub_request(:post, 'https://example.org:443/account/fee')
|
474
|
+
.with(
|
475
|
+
headers: { 'X-Zerocracy-Token' => '000' },
|
476
|
+
body: {
|
477
|
+
'_csrf' => 'csrf-token',
|
478
|
+
'tab' => 'unknown',
|
479
|
+
'amount' => '10.500000',
|
480
|
+
'summary' => 'Test fee',
|
481
|
+
'job' => '123'
|
482
|
+
}
|
483
|
+
)
|
484
|
+
.to_return(status: 302, headers: { 'X-Zerocracy-ReceiptId' => '456' })
|
485
|
+
receipt = fake_baza.fee('unknown', 10.5, 'Test fee', 123)
|
486
|
+
assert_equal(456, receipt)
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_enter
|
490
|
+
WebMock.disable_net_connect!
|
491
|
+
stub_request(:get, 'https://example.org:443/valves/result?badge=test-badge')
|
492
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
493
|
+
.to_return(status: 200, body: 'cached result')
|
494
|
+
result = fake_baza.enter('test-valve', 'test-badge', 'test reason', 123) { 'new result' }
|
495
|
+
assert_equal('cached result', result)
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_enter_not_cached
|
499
|
+
WebMock.disable_net_connect!
|
500
|
+
stub_request(:get, 'https://example.org:443/valves/result?badge=test-badge')
|
501
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
502
|
+
.to_return(status: 204)
|
503
|
+
stub_request(:get, 'https://example.org:443/csrf')
|
504
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
505
|
+
.to_return(status: 200, body: 'csrf-token')
|
506
|
+
stub_request(:post, 'https://example.org:443/valves/add?job=123')
|
507
|
+
.with(
|
508
|
+
headers: { 'X-Zerocracy-Token' => '000' },
|
509
|
+
body: {
|
510
|
+
'_csrf' => 'csrf-token',
|
511
|
+
'name' => 'test-valve',
|
512
|
+
'badge' => 'test-badge',
|
513
|
+
'why' => 'test reason',
|
514
|
+
'result' => 'new result'
|
515
|
+
}
|
516
|
+
)
|
517
|
+
.to_return(status: 302)
|
518
|
+
result = fake_baza.enter('test-valve', 'test-badge', 'test reason', 123) { 'new result' }
|
519
|
+
assert_equal('new result', result)
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_checked_with_500_error
|
523
|
+
WebMock.disable_net_connect!
|
524
|
+
stub_request(:get, 'https://example.org:443/test')
|
525
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
526
|
+
.to_return(status: 500)
|
527
|
+
error =
|
528
|
+
assert_raises(BazaRb::ServerFailure) do
|
529
|
+
fake_baza.send(
|
530
|
+
:checked,
|
531
|
+
Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
|
532
|
+
)
|
533
|
+
end
|
534
|
+
assert_includes(error.message, 'Invalid response code #500')
|
535
|
+
assert_includes(error.message, "most probably it's an internal error on the server")
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_checked_with_503_error
|
539
|
+
WebMock.disable_net_connect!
|
540
|
+
stub_request(:get, 'https://example.org:443/test')
|
541
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
542
|
+
.to_return(status: 503, headers: { 'X-Zerocracy-Failure' => 'Service unavailable' })
|
543
|
+
error =
|
544
|
+
assert_raises(BazaRb::ServerFailure) do
|
545
|
+
fake_baza.send(
|
546
|
+
:checked,
|
547
|
+
Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
|
548
|
+
)
|
549
|
+
end
|
550
|
+
assert_includes(error.message, 'Invalid response code #503')
|
551
|
+
assert_includes(error.message, "most probably it's an internal error on the server")
|
552
|
+
assert_includes(error.message, 'Service unavailable')
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_checked_with_404_error
|
556
|
+
WebMock.disable_net_connect!
|
557
|
+
stub_request(:get, 'https://example.org:443/test')
|
558
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
559
|
+
.to_return(status: 404)
|
560
|
+
error =
|
561
|
+
assert_raises(BazaRb::ServerFailure) do
|
562
|
+
fake_baza.send(
|
563
|
+
:checked,
|
564
|
+
Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
|
565
|
+
)
|
566
|
+
end
|
567
|
+
assert_includes(error.message, 'Invalid response code #404')
|
568
|
+
assert_includes(error.message, 'most probably you are trying to reach a wrong server')
|
569
|
+
end
|
570
|
+
|
571
|
+
def test_checked_with_0_error
|
572
|
+
WebMock.disable_net_connect!
|
573
|
+
stub_request(:get, 'https://example.org:443/test')
|
574
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
575
|
+
.to_return(status: 0)
|
576
|
+
error =
|
577
|
+
assert_raises(BazaRb::ServerFailure) do
|
578
|
+
fake_baza.send(
|
579
|
+
:checked,
|
580
|
+
Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
|
581
|
+
)
|
582
|
+
end
|
583
|
+
assert_includes(error.message, 'Invalid response code #0')
|
584
|
+
assert_includes(error.message, 'most likely a connection failure')
|
585
|
+
end
|
586
|
+
|
587
|
+
def test_push_without_compression
|
588
|
+
WebMock.disable_net_connect!
|
589
|
+
baza = BazaRb.new('example.org', 443, '000', loog: Loog::NULL, compress: false)
|
590
|
+
stub_request(:put, 'https://example.org:443/push/test')
|
591
|
+
.with(
|
592
|
+
headers: {
|
593
|
+
'X-Zerocracy-Token' => '000',
|
594
|
+
'Content-Type' => 'application/octet-stream',
|
595
|
+
'Content-Length' => '4'
|
596
|
+
},
|
597
|
+
body: 'data'
|
598
|
+
)
|
599
|
+
.to_return(status: 200, body: '123')
|
600
|
+
id = baza.push('test', 'data', [])
|
601
|
+
assert_equal(123, id)
|
602
|
+
end
|
603
|
+
|
342
604
|
private
|
343
605
|
|
344
606
|
def with_http_server(code, response, opts = {})
|
345
607
|
opts = { ssl: false, timeout: 1 }.merge(opts)
|
346
608
|
WebMock.enable_net_connect!
|
347
|
-
skip('We are offline') unless we_are_online
|
348
609
|
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
349
610
|
host = '127.0.0.1'
|
350
611
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
@@ -353,21 +614,44 @@ class TestBazaRb < Minitest::Test
|
|
353
614
|
Thread.new do
|
354
615
|
socket = server.accept
|
355
616
|
req.parse(socket)
|
356
|
-
req.body
|
357
|
-
|
617
|
+
body = req.body
|
618
|
+
len = req.header['content-length'].first.to_i
|
619
|
+
if body.nil? || len == body.size
|
620
|
+
socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
|
621
|
+
else
|
622
|
+
socket.puts "HTTP/1.1 400 Bad Request\r\n"
|
623
|
+
end
|
358
624
|
socket.close
|
359
625
|
end
|
360
626
|
yield BazaRb.new(host, port, '0000', **opts)
|
361
|
-
t.
|
627
|
+
t.terminate
|
628
|
+
assert(t.join(1))
|
362
629
|
end
|
363
630
|
req
|
364
631
|
end
|
365
632
|
|
633
|
+
def fake_baza
|
634
|
+
BazaRb.new('example.org', 443, '000', loog: Loog::NULL)
|
635
|
+
end
|
636
|
+
|
366
637
|
def fake_name
|
367
638
|
"fake#{SecureRandom.hex(8)}"
|
368
639
|
end
|
369
640
|
|
370
641
|
def we_are_online
|
371
|
-
|
642
|
+
$we_are_online ||= !ARGV.include?('--offline') && uri_is_alive('https://www.zerocracy.com')
|
643
|
+
end
|
644
|
+
# rubocop:enable Style/GlobalVars
|
645
|
+
|
646
|
+
# Checks whether this URI is alive (HTTP status is 200).
|
647
|
+
def uri_is_alive(uri)
|
648
|
+
Timeout.timeout(4) do
|
649
|
+
require 'net/http'
|
650
|
+
WebMock.enable_net_connect!
|
651
|
+
Net::HTTP.get_response(URI(uri)).is_a?(Net::HTTPSuccess)
|
652
|
+
rescue Timeout::Error, Timeout::ExitException, Socket::ResolutionError, Errno::EHOSTUNREACH, Errno::EINVAL
|
653
|
+
puts "Ping failed to #{uri}"
|
654
|
+
false
|
655
|
+
end
|
372
656
|
end
|
373
657
|
end
|
data/test/test_fake.rb
CHANGED
@@ -8,7 +8,7 @@ require_relative '../lib/baza-rb/fake'
|
|
8
8
|
|
9
9
|
# Test fake object.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
11
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
13
|
class TestFake < Minitest::Test
|
14
14
|
def test_whoami
|
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.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: backtrace
|
@@ -163,15 +163,15 @@ dependencies:
|
|
163
163
|
- - "~>"
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '1.3'
|
166
|
-
description: It is a Ruby client for Zerocracy API, allowing you to check your
|
166
|
+
description: It is a Ruby client for Zerocracy API, allowing you to check your job
|
167
167
|
statuses, upload and download binaries, lock/unlock them, manage durables, and do
|
168
168
|
everything else that is possible to do via the HTTP API.
|
169
169
|
email: yegor256@gmail.com
|
170
170
|
executables: []
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files:
|
173
|
-
- README.md
|
174
173
|
- LICENSE.txt
|
174
|
+
- README.md
|
175
175
|
files:
|
176
176
|
- ".0pdd.yml"
|
177
177
|
- ".gitattributes"
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- ".github/workflows/pdd.yml"
|
183
183
|
- ".github/workflows/rake.yml"
|
184
184
|
- ".github/workflows/reuse.yml"
|
185
|
+
- ".github/workflows/typos.yml"
|
185
186
|
- ".github/workflows/xcop.yml"
|
186
187
|
- ".github/workflows/yamllint.yml"
|
187
188
|
- ".gitignore"
|
@@ -225,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
226
|
- !ruby/object:Gem::Version
|
226
227
|
version: '0'
|
227
228
|
requirements: []
|
228
|
-
rubygems_version: 3.6.
|
229
|
+
rubygems_version: 3.6.7
|
229
230
|
specification_version: 4
|
230
231
|
summary: Zerocracy API Ruby Client
|
231
232
|
test_files: []
|