zold 0.32.0 → 0.32.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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/zold/version.rb +1 -1
  4. data/zold.gemspec +1 -1
  5. metadata +2 -168
  6. data/.0pdd.yml +0 -12
  7. data/.gitattributes +0 -9
  8. data/.github/typos.toml +0 -11
  9. data/.github/workflows/actionlint.yml +0 -25
  10. data/.github/workflows/bashate.yml +0 -25
  11. data/.github/workflows/codecov.yml +0 -27
  12. data/.github/workflows/copyrights.yml +0 -15
  13. data/.github/workflows/hadolint.yml +0 -14
  14. data/.github/workflows/markdown-lint.yml +0 -19
  15. data/.github/workflows/pdd.yml +0 -19
  16. data/.github/workflows/rake.yml +0 -31
  17. data/.github/workflows/reuse.yml +0 -19
  18. data/.github/workflows/shellcheck.yml +0 -19
  19. data/.github/workflows/typos.yml +0 -21
  20. data/.github/workflows/xcop.yml +0 -15
  21. data/.github/workflows/yamllint.yml +0 -19
  22. data/.gitignore +0 -15
  23. data/.pdd +0 -7
  24. data/.rubocop.yml +0 -66
  25. data/.ruby-version +0 -1
  26. data/.rultor.yml +0 -41
  27. data/cucumber.yml +0 -6
  28. data/features/cli.feature +0 -18
  29. data/features/gem_package.feature +0 -28
  30. data/features/step_definitions/steps.rb +0 -67
  31. data/features/support/env.rb +0 -9
  32. data/fixtures/448b451bc62e8e16.z +0 -1005
  33. data/fixtures/id_rsa +0 -51
  34. data/fixtures/id_rsa-2 +0 -51
  35. data/fixtures/id_rsa-2.pub +0 -1
  36. data/fixtures/id_rsa.pub +0 -1
  37. data/fixtures/keys/1.pub +0 -1
  38. data/fixtures/keys/2 +0 -51
  39. data/fixtures/keys/2.pub +0 -1
  40. data/fixtures/merge/asserts.rb +0 -20
  41. data/fixtures/merge/id_rsa +0 -51
  42. data/fixtures/merge/id_rsa.pub +0 -1
  43. data/fixtures/merge/into_no_wallet/assert.rb +0 -8
  44. data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/1.zc +0 -6
  45. data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/scores.zc +0 -1
  46. data/fixtures/merge/into_no_wallet/opts +0 -1
  47. data/fixtures/merge/legacy_negatives_stay/0123456789abcdef.z +0 -6
  48. data/fixtures/merge/legacy_negatives_stay/assert.rb +0 -8
  49. data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/1.zc +0 -6
  50. data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +0 -1
  51. data/fixtures/merge/legacy_negatives_stay/opts +0 -2
  52. data/fixtures/merge/missed_wallets/0000000000000000.z +0 -6
  53. data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -4
  54. data/fixtures/merge/missed_wallets/assert.rb +0 -8
  55. data/fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc +0 -8
  56. data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +0 -1
  57. data/fixtures/merge/missed_wallets/opts +0 -3
  58. data/fixtures/merge/negative_overwriting/0123456789abcdef.z +0 -6
  59. data/fixtures/merge/negative_overwriting/146b852f2d9ad984.z +0 -6
  60. data/fixtures/merge/negative_overwriting/assert.rb +0 -8
  61. data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/1.zc +0 -6
  62. data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/scores.zc +0 -1
  63. data/fixtures/merge/negative_overwriting/opts +0 -2
  64. data/fixtures/merge/negatives_in_between/0000000000000000.z +0 -6
  65. data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -4
  66. data/fixtures/merge/negatives_in_between/assert.rb +0 -8
  67. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc +0 -6
  68. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -6
  69. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc +0 -6
  70. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc +0 -3
  71. data/fixtures/merge/negatives_in_between/opts +0 -1
  72. data/fixtures/merge/random_expenses/0000000000000000.z +0 -6
  73. data/fixtures/merge/random_expenses/0123456789abcdef.z +0 -6
  74. data/fixtures/merge/random_expenses/assert.rb +0 -8
  75. data/fixtures/merge/random_expenses/copies/0123456789abcdef/1.zc +0 -7
  76. data/fixtures/merge/random_expenses/copies/0123456789abcdef/2.zc +0 -7
  77. data/fixtures/merge/random_expenses/copies/0123456789abcdef/3.zc +0 -7
  78. data/fixtures/merge/random_expenses/copies/0123456789abcdef/4.zc +0 -7
  79. data/fixtures/merge/random_expenses/copies/0123456789abcdef/5.zc +0 -7
  80. data/fixtures/merge/random_expenses/copies/0123456789abcdef/scores.zc +0 -5
  81. data/fixtures/merge/random_expenses/opts +0 -1
  82. data/fixtures/merge/simple_case/0000000000000000.z +0 -6
  83. data/fixtures/merge/simple_case/0123456789abcdef.z +0 -4
  84. data/fixtures/merge/simple_case/assert.rb +0 -8
  85. data/fixtures/merge/simple_case/copies/0123456789abcdef/1.zc +0 -6
  86. data/fixtures/merge/simple_case/copies/0123456789abcdef/scores.zc +0 -1
  87. data/fixtures/merge/simple_case/opts +0 -1
  88. data/fixtures/merge/unconfirmed_income/0123456789abcdef.z +0 -4
  89. data/fixtures/merge/unconfirmed_income/assert.rb +0 -8
  90. data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/1.zc +0 -6
  91. data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/scores.zc +0 -1
  92. data/fixtures/merge/unconfirmed_income/opts +0 -3
  93. data/fixtures/scripts/_head.sh +0 -72
  94. data/fixtures/scripts/calculate-scores.sh +0 -5
  95. data/fixtures/scripts/distribute-wallet.sh +0 -88
  96. data/fixtures/scripts/print-helps.sh +0 -9
  97. data/fixtures/scripts/pull-on-start.sh +0 -35
  98. data/fixtures/scripts/push-and-pull.sh +0 -46
  99. data/fixtures/scripts/redeploy-on-upgrade.sh +0 -40
  100. data/fixtures/scripts/spread-wallets.sh +0 -56
  101. data/renovate.json +0 -6
  102. data/test/commands/routines/test_audit.rb +0 -23
  103. data/test/commands/routines/test_gc.rb +0 -52
  104. data/test/commands/routines/test_reconcile.rb +0 -33
  105. data/test/commands/routines/test_reconnect.rb +0 -28
  106. data/test/commands/routines/test_retire.rb +0 -22
  107. data/test/commands/test_alias.rb +0 -58
  108. data/test/commands/test_calculate.rb +0 -22
  109. data/test/commands/test_clean.rb +0 -55
  110. data/test/commands/test_create.rb +0 -32
  111. data/test/commands/test_diff.rb +0 -43
  112. data/test/commands/test_fetch.rb +0 -144
  113. data/test/commands/test_invoice.rb +0 -32
  114. data/test/commands/test_list.rb +0 -29
  115. data/test/commands/test_merge.rb +0 -106
  116. data/test/commands/test_node.rb +0 -50
  117. data/test/commands/test_pay.rb +0 -203
  118. data/test/commands/test_propagate.rb +0 -33
  119. data/test/commands/test_pull.rb +0 -52
  120. data/test/commands/test_push.rb +0 -75
  121. data/test/commands/test_remote.rb +0 -247
  122. data/test/commands/test_remove.rb +0 -48
  123. data/test/commands/test_show.rb +0 -30
  124. data/test/commands/test_taxes.rb +0 -58
  125. data/test/fake_home.rb +0 -87
  126. data/test/node/fake_entrance.rb +0 -26
  127. data/test/node/fake_node.rb +0 -88
  128. data/test/node/test_async_entrance.rb +0 -85
  129. data/test/node/test_entrance.rb +0 -64
  130. data/test/node/test_farm.rb +0 -159
  131. data/test/node/test_farmers.rb +0 -58
  132. data/test/node/test_front.rb +0 -379
  133. data/test/node/test_nodup_entrance.rb +0 -31
  134. data/test/node/test_nospam_entrance.rb +0 -31
  135. data/test/node/test_safe_entrance.rb +0 -41
  136. data/test/node/test_spread_entrance.rb +0 -49
  137. data/test/node/test_sync_entrance.rb +0 -23
  138. data/test/node/test_trace.rb +0 -18
  139. data/test/test__helper.rb +0 -113
  140. data/test/test_age.rb +0 -37
  141. data/test/test_amount.rb +0 -62
  142. data/test/test_cached_wallets.rb +0 -55
  143. data/test/test_copies.rb +0 -127
  144. data/test/test_dir_items.rb +0 -72
  145. data/test/test_gem.rb +0 -23
  146. data/test/test_hands.rb +0 -51
  147. data/test/test_hexnum.rb +0 -18
  148. data/test/test_http.rb +0 -207
  149. data/test/test_hungry_wallets.rb +0 -72
  150. data/test/test_id.rb +0 -61
  151. data/test/test_json_page.rb +0 -29
  152. data/test/test_key.rb +0 -81
  153. data/test/test_metronome.rb +0 -71
  154. data/test/test_patch.rb +0 -160
  155. data/test/test_prefixes.rb +0 -31
  156. data/test/test_remotes.rb +0 -301
  157. data/test/test_signature.rb +0 -31
  158. data/test/test_size.rb +0 -21
  159. data/test/test_sync_wallets.rb +0 -39
  160. data/test/test_tax.rb +0 -153
  161. data/test/test_thread_pool.rb +0 -71
  162. data/test/test_tree_wallets.rb +0 -65
  163. data/test/test_txn.rb +0 -71
  164. data/test/test_upgrades.rb +0 -81
  165. data/test/test_verbose_thread.rb +0 -37
  166. data/test/test_version.rb +0 -17
  167. data/test/test_wallet.rb +0 -300
  168. data/test/test_wallets.rb +0 -67
  169. data/test/test_zold.rb +0 -81
  170. data/test/upgrades/test_delete_banned_wallets.rb +0 -29
  171. data/test/upgrades/test_protocol_up.rb +0 -24
data/test/test_age.rb DELETED
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require_relative 'test__helper'
7
- require_relative '../lib/zold/age'
8
-
9
- # Age test.
10
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
12
- # License:: MIT
13
- class TestAge < Zold::Test
14
- def test_prints_age
15
- assert_equal('10m', Zold::Age.new(Time.now - (10 * 60)).to_s)
16
- assert_equal('5.5s', Zold::Age.new(Time.now - 5.5).to_s)
17
- assert_equal('?', Zold::Age.new(nil).to_s)
18
- refute_nil(Zold::Age.new(Time.now.utc.iso8601).to_s)
19
- end
20
-
21
- def test_prints_all_ages
22
- [
23
- 0,
24
- 1,
25
- 63,
26
- 63 * 60,
27
- 27 * 60 * 60,
28
- 13 * 24 * 60 * 60,
29
- 30 * 24 * 60 * 60,
30
- 5 * 30 * 24 * 60 * 60,
31
- 15 * 30 * 24 * 60 * 60,
32
- 8 * 12 * 30 * 24 * 60 * 60
33
- ].each do |s|
34
- refute_nil(Zold::Age.new(Time.now - s).to_s)
35
- end
36
- end
37
- end
data/test/test_amount.rb DELETED
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require_relative 'test__helper'
7
- require_relative '../lib/zold/amount'
8
-
9
- # Amount test.
10
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
12
- # License:: MIT
13
- class TestAmount < Zold::Test
14
- def test_parses_zld
15
- amount = Zold::Amount.new(zld: 14.95)
16
- assert_includes(
17
- amount.to_s, '14.95ZLD',
18
- "#{amount} is not equal to '14.95ZLD'"
19
- )
20
- end
21
-
22
- def test_prints_zld_with_many_digits
23
- amount = Zold::Amount.new(zld: 0.12345678)
24
- assert_equal('0.123', amount.to_zld(3))
25
- assert_equal('0.1235', amount.to_zld(4))
26
- assert_equal('0.12346', amount.to_zld(5))
27
- assert_equal('0.123457', amount.to_zld(6))
28
- end
29
-
30
- def test_compares_with_zero
31
- amount = Zold::Amount.new(zld: 0.00001)
32
- refute_predicate(amount, :zero?)
33
- assert_predicate(amount, :positive?)
34
- refute_predicate(amount, :negative?)
35
- refute_equal(amount, Zold::Amount::ZERO)
36
- end
37
-
38
- def test_parses_zents
39
- amount = Zold::Amount.new(zents: 900_000_000)
40
- assert_includes(
41
- amount.to_s, '0.21ZLD',
42
- "#{amount} is not equal to '0.21ZLD'"
43
- )
44
- end
45
-
46
- def test_compares_amounts
47
- amount = Zold::Amount.new(zents: 700_000_000)
48
- assert_operator(
49
- amount, :>, Zold::Amount::ZERO, "#{amount} is not greater than zero"
50
- )
51
- end
52
-
53
- def test_multiplies
54
- amount = Zold::Amount.new(zld: 1.2)
55
- assert_equal(Zold::Amount.new(zld: 2.4), amount * 2)
56
- end
57
-
58
- def test_divides
59
- amount = Zold::Amount.new(zld: 8.2)
60
- assert_equal(Zold::Amount.new(zld: 4.1), amount / 2)
61
- end
62
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'tmpdir'
7
- require_relative 'test__helper'
8
- require_relative 'fake_home'
9
- require_relative '../lib/zold/key'
10
- require_relative '../lib/zold/id'
11
- require_relative '../lib/zold/wallets'
12
- require_relative '../lib/zold/cached_wallets'
13
- require_relative '../lib/zold/amount'
14
-
15
- # CachedWallets test.
16
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
17
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
18
- # License:: MIT
19
- class TestCachedWallets < Zold::Test
20
- def test_adds_wallet
21
- Dir.mktmpdir do |dir|
22
- wallets = Zold::CachedWallets.new(Zold::Wallets.new(dir))
23
- id = Zold::Id.new
24
- first = nil
25
- wallets.acq(id, exclusive: true) do |wallet|
26
- wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
27
- assert_equal(1, wallets.all.count)
28
- first = wallet
29
- end
30
- wallets.acq(id) do |wallet|
31
- assert_equal(first, wallet)
32
- end
33
- end
34
- end
35
-
36
- def test_flushes_correctly
37
- Dir.mktmpdir do |dir|
38
- wallets = Zold::CachedWallets.new(Zold::Wallets.new(dir))
39
- id = Zold::Id.new
40
- key = Zold::Key.new(file: 'fixtures/id_rsa')
41
- body = wallets.acq(id, exclusive: true) do |wallet|
42
- wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
43
- File.read(wallet.path)
44
- end
45
- wallets.acq(id, exclusive: true) do |wallet|
46
- wallet.sub(Zold::Amount.new(zld: 1.0), "NOPREFIX@#{Zold::Id.new}", key)
47
- end
48
- assert_equal(1, wallets.acq(id, &:txns).count)
49
- wallets.acq(id, exclusive: true) do |wallet|
50
- File.write(wallet.path, body)
51
- end
52
- assert_equal(0, wallets.acq(id, &:txns).count)
53
- end
54
- end
55
- end
data/test/test_copies.rb DELETED
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'tmpdir'
7
- require 'time'
8
- require_relative 'fake_home'
9
- require_relative 'test__helper'
10
- require_relative '../lib/zold/id'
11
- require_relative '../lib/zold/age'
12
- require_relative '../lib/zold/copies'
13
- require_relative '../lib/zold/dir_items'
14
- require_relative '../lib/zold/wallet'
15
-
16
- # Copies test.
17
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
18
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
19
- # License:: MIT
20
- class TestCopies < Zold::Test
21
- def test_adds_and_removes_copies
22
- Dir.mktmpdir do |dir|
23
- copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log: fake_log)
24
- copies.add(content('alpha'), '192.168.0.1', 80, 1)
25
- copies.add(content('beta'), '192.168.0.2', 80, 3)
26
- copies.add(content('beta'), '192.168.0.3', 80, 7)
27
- copies.add(content('alpha'), '192.168.0.4', 80, 10)
28
- copies.add(content('hello-to-delete'), '192.168.0.5', 80, 10)
29
- copies.remove('192.168.0.5', 80)
30
- copies.clean
31
- assert_equal(2, copies.all.count, copies.all.map { |c| c[:name] }.join('; '))
32
- assert_equal(11, copies.all.find { |c| c[:name] == '1' }[:score])
33
- end
34
- end
35
-
36
- def test_lists_empty_dir
37
- Dir.mktmpdir do |dir|
38
- copies = Zold::Copies.new(File.join(dir, 'xxx'), log: fake_log)
39
- assert_empty(copies.all, "#{copies.all.count} is not zero")
40
- end
41
- end
42
-
43
- def test_overwrites_host
44
- Dir.mktmpdir do |dir|
45
- copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log)
46
- host = 'b1.zold.io'
47
- copies.add(content('z1'), host, 80, 5)
48
- copies.add(content('z1'), host, 80, 6)
49
- copies.add(content('z1'), host, 80, 7)
50
- assert_predicate(copies.all, :one?, "#{copies.all.count} is not equal to 1")
51
- assert_equal(7, copies.all[0][:score], "#{copies.all[0][:score]} is not 7")
52
- end
53
- end
54
-
55
- def test_master_first
56
- Dir.mktmpdir do |dir|
57
- copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log)
58
- copies.add(content('z1'), 'edge-1', 80, 100, master: false)
59
- copies.add(content('z2'), 'master', 80, 1, master: true)
60
- copies.add(content('z1'), 'edge-2', 80, 50, master: false)
61
- copies.add(content('z1'), 'edge-3', 80, 400, master: false)
62
- assert(copies.all[0][:master])
63
- end
64
- end
65
-
66
- def test_cleans_copies
67
- Dir.mktmpdir do |dir|
68
- copies = Zold::Copies.new(dir, log: fake_log)
69
- copies.add(content('h1'), 'zold.io', 4096, 10, time: Time.now - (25 * 60 * 60))
70
- copies.add(content('h1'), 'zold.io', 4097, 20, time: Time.now - (26 * 60 * 60))
71
- assert_path_exists(File.join(dir, "1#{Zold::Copies::EXT}"))
72
- copies.clean
73
- assert_empty(copies.all, "#{copies.all.count} is not empty")
74
- refute_path_exists(File.join(dir, "1#{Zold::Copies::EXT}"))
75
- end
76
- end
77
-
78
- def test_cleans_broken_copies
79
- Dir.mktmpdir do |dir|
80
- copies = Zold::Copies.new(dir, log: fake_log)
81
- copies.add('broken wallet content', 'zold.io', 4096, 10, time: Time.now)
82
- copies.clean
83
- assert_empty(copies.all, "#{copies.all.count} is not empty")
84
- end
85
- end
86
-
87
- def test_ignores_garbage
88
- Dir.mktmpdir do |dir|
89
- copies = Zold::Copies.new(dir, log: fake_log)
90
- copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (25 * 60 * 60))
91
- FileUtils.mkdir(File.join(dir, '55'))
92
- assert_equal(1, copies.all.count)
93
- end
94
- end
95
-
96
- def test_sorts_them_by_score
97
- Dir.mktmpdir do |dir|
98
- copies = Zold::Copies.new(dir, log: fake_log)
99
- copies.add(content('content-1'), '1.zold.io', 80, 1)
100
- copies.add(content('content-2'), '2.zold.io', 80, 2)
101
- copies.add(content('content-3'), '3.zold.io', 80, 50)
102
- copies.add(content('content-4'), '4.zold.io', 80, 3)
103
- assert_equal('50 3 2 1', copies.all.map { |c| c[:score] }.join(' '))
104
- end
105
- end
106
-
107
- def test_ignores_too_old_scores
108
- Dir.mktmpdir do |dir|
109
- copies = Zold::Copies.new(dir, log: fake_log)
110
- copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (1000 * 60 * 60))
111
- assert_equal(0, copies.all[0][:score])
112
- end
113
- end
114
-
115
- private
116
-
117
- def content(text)
118
- id = Zold::Id.new('aaaabbbbccccdddd')
119
- FakeHome.new(log: fake_log).run do |home|
120
- wallet = home.create_wallet(id)
121
- amount = Zold::Amount.new(zld: 1.99)
122
- key = Zold::Key.new(file: 'fixtures/id_rsa')
123
- wallet.sub(amount, 'NOPREFIX@0000111122223333', key, text, time: Time.parse('2018-01-01T01:01:01Z'))
124
- File.read(wallet.path)
125
- end
126
- end
127
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'tmpdir'
7
- require 'threads'
8
- require_relative 'test__helper'
9
- require_relative '../lib/zold/age'
10
- require_relative '../lib/zold/endless'
11
- require_relative '../lib/zold/dir_items'
12
-
13
- # DirItems test.
14
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
16
- # License:: MIT
17
- class TestDirItems < Zold::Test
18
- def test_intensive_write_in_threads
19
- Dir.mktmpdir do |dir|
20
- file = File.join(dir, 'hey.txt')
21
- back = Thread.start do
22
- Zold::Endless.new('test-diritems', log: fake_log).run do
23
- Zold::DirItems.new(dir).fetch
24
- end
25
- end
26
- Threads.new(100).assert do
27
- start = Time.now
28
- File.write(file, 'test')
29
- fake_log.info("Saved in #{Zold::Age.new(start)}")
30
- sleep 1
31
- end
32
- back.kill
33
- end
34
- end
35
-
36
- def test_lists_empty_dir
37
- Dir.mktmpdir do |dir|
38
- d = File.join(dir, 'path с пробелами')
39
- FileUtils.mkdir_p(d)
40
- assert_equal(0, Zold::DirItems.new(d).fetch.count)
41
- end
42
- end
43
-
44
- def test_lists_recursively
45
- Dir.mktmpdir do |dir|
46
- files = ['test1.txt', 'a/b/c/text', 'd/e/f/text', 'a/b/c/zz/text.1.2.3']
47
- files.each do |f|
48
- path = File.join(dir, f)
49
- FileUtils.mkdir_p(File.dirname(path))
50
- FileUtils.touch(path)
51
- end
52
- found = Zold::DirItems.new(dir).fetch
53
- assert_equal(files.count, found.count)
54
- files.each do |f|
55
- assert_includes(found, f, f)
56
- end
57
- end
58
- end
59
-
60
- def test_lists_non_recursively
61
- Dir.mktmpdir do |dir|
62
- files = ['1.txt', 'a/1.txt', 'a/b/1.txt', 'a/b/c/1.txt']
63
- files.each do |f|
64
- path = File.join(dir, f)
65
- FileUtils.mkdir_p(File.dirname(path))
66
- FileUtils.touch(path)
67
- end
68
- found = Zold::DirItems.new(dir).fetch(recursive: false)
69
- assert_equal(1, found.count)
70
- end
71
- end
72
- end
data/test/test_gem.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require_relative '../lib/zold/gem'
7
- require 'webmock/minitest'
8
-
9
- class TestGem < Zold::Test
10
- def test_last_version
11
- version = (1..3).map { rand(9).to_s }.join('.')
12
- stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
13
- status: 200,
14
- body: "{\"version\": \"#{version}\"}"
15
- )
16
- assert_equal(version, Zold::Gem.new.last_version)
17
- end
18
-
19
- def test_last_version_live
20
- WebMock.allow_net_connect!
21
- refute_nil(Zold::Gem.new.last_version)
22
- end
23
- end
data/test/test_hands.rb DELETED
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'concurrent'
7
- require_relative 'test__helper'
8
- require_relative '../lib/zold/hands'
9
-
10
- # Hands test.
11
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
12
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
13
- # License:: MIT
14
- class TestHands < Zold::Test
15
- def test_runs_in_many_threads
16
- idx = Concurrent::AtomicFixnum.new
17
- threads = 50
18
- Zold::Hands.exec(threads) do
19
- idx.increment
20
- end
21
- assert_equal(threads, idx.value)
22
- end
23
-
24
- def test_runs_with_empty_set
25
- Zold::Hands.exec(5, []) do
26
- # nothing
27
- end
28
- end
29
-
30
- def test_runs_with_index
31
- idx = Concurrent::AtomicFixnum.new
32
- indexes = Set.new
33
- Zold::Hands.exec(10, %w[a b c]) do |_, i|
34
- idx.increment
35
- indexes << i
36
- end
37
- assert_equal(3, idx.value)
38
- assert_equal('0 1 2', indexes.to_a.sort.join(' '))
39
- end
40
-
41
- def test_runs_with_exceptions
42
- assert_raises do
43
- Zold::Hands.exec(5) do |i|
44
- if i == 4
45
- sleep 0.1
46
- raise 'intended'
47
- end
48
- end
49
- end
50
- end
51
- end
data/test/test_hexnum.rb DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require_relative '../lib/zold/hexnum'
7
-
8
- # Hexnum test.
9
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
10
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
11
- # License:: MIT
12
- class TestHexnum < Zold::Test
13
- def test_prints_and_parses
14
- [0, 1, 3, 5, 7, 13, 6447, 897_464, -1, -3, -7584, -900_098].each do |n|
15
- assert_equal(n, Zold::Hexnum.parse(Zold::Hexnum.new(n, 6).to_s).to_i)
16
- end
17
- end
18
- end
data/test/test_http.rb DELETED
@@ -1,207 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'tmpdir'
7
- require 'uri'
8
- require 'webmock/minitest'
9
- require 'zold/score'
10
- require 'random-port'
11
- require_relative 'test__helper'
12
- require_relative '../lib/zold/http'
13
- require_relative '../lib/zold/verbose_thread'
14
-
15
- # Http test.
16
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
17
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
18
- # License:: MIT
19
- class TestHttp < Zold::Test
20
- def test_pings_broken_uri
21
- stub_request(:get, 'http://bad-host/').to_return(status: 500)
22
- res = Zold::Http.new(uri: 'http://bad-host/').get
23
- assert_equal(500, res.status)
24
- assert_equal('', res.body)
25
- end
26
-
27
- def test_pings_with_exception
28
- stub_request(:get, 'http://exception/').to_return { raise 'Intentionally' }
29
- res = Zold::Http.new(uri: 'http://exception/').get
30
- assert_equal(599, res.status)
31
- assert_includes(res.body, 'Intentionally')
32
- refute(res.headers['nothing'])
33
- end
34
-
35
- def test_pings_live_uri
36
- stub_request(:get, 'http://good-host/').to_return(status: 200)
37
- res = Zold::Http.new(uri: 'http://good-host/').get
38
- assert_equal(200, res.status)
39
- end
40
-
41
- def test_sends_valid_network_header
42
- stub_request(:get, 'http://some-host-1/')
43
- .with(headers: { 'X-Zold-Network' => 'xyz' })
44
- .to_return(status: 200)
45
- res = Zold::Http.new(uri: 'http://some-host-1/', network: 'xyz').get
46
- assert_equal(200, res.status)
47
- end
48
-
49
- def test_sends_valid_protocol_header
50
- stub_request(:get, 'http://some-host-2/')
51
- .with(headers: { 'X-Zold-Protocol' => Zold::PROTOCOL })
52
- .to_return(status: 200)
53
- res = Zold::Http.new(uri: 'http://some-host-2/').get
54
- assert_equal(200, res.status)
55
- end
56
-
57
- def test_terminates_on_timeout
58
- WebMock.allow_net_connect!
59
- RandomPort::Pool::SINGLETON.acquire do |port|
60
- thread = Thread.start do
61
- Zold::VerboseThread.new(fake_log).run do
62
- server = TCPServer.new(port)
63
- server.accept
64
- sleep 400
65
- end
66
- end
67
- sleep 0.25
68
- res = Zold::Http.new(uri: "http://127.0.0.1:#{port}/").get(timeout: 0.1)
69
- assert_equal(599, res.status, res)
70
- assert_equal('', res.status_line, res)
71
- thread.kill
72
- thread.join
73
- end
74
- end
75
-
76
- def test_doesnt_terminate_on_long_call
77
- WebMock.allow_net_connect!
78
- RandomPort::Pool::SINGLETON.acquire do |port|
79
- thread = Thread.start do
80
- Zold::VerboseThread.new(fake_log).run do
81
- server = TCPServer.new(port)
82
- client = server.accept
83
- client.puts("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n")
84
- sleep 1
85
- client.puts('Good')
86
- client.close
87
- end
88
- end
89
- sleep 0.25
90
- res = Zold::Http.new(uri: "http://127.0.0.1:#{port}/").get(timeout: 2)
91
- assert_equal(200, res.status, res)
92
- thread.kill
93
- thread.join
94
- end
95
- end
96
-
97
- def test_sends_correct_http_headers
98
- WebMock.allow_net_connect!
99
- body = ''
100
- RandomPort::Pool::SINGLETON.acquire do |port|
101
- latch = Concurrent::CountDownLatch.new(1)
102
- thread = Thread.start do
103
- Zold::VerboseThread.new(fake_log).run do
104
- server = TCPServer.new('127.0.0.1', port)
105
- latch.count_down
106
- socket = server.accept
107
- loop do
108
- line = socket.gets
109
- break if line.eql?("\r\n")
110
- fake_log.info(line.inspect)
111
- body += line
112
- end
113
- socket.print("HTTP/1.1 200 OK\r\n")
114
- socket.print("Content-Length: 4\r\n")
115
- socket.print("\r\n")
116
- socket.print('Done')
117
- socket.close
118
- end
119
- end
120
- latch.wait
121
- res = Tempfile.open do |f|
122
- File.write(f, 'How are you?')
123
- Zold::Http.new(uri: "http://127.0.0.1:#{port}/").put(f)
124
- end
125
- assert_equal(200, res.status, res)
126
- assert_includes(body, 'Content-Length: 12', body)
127
- assert_includes(body, 'Content-Type: text/plain')
128
- headers = body.split("\n").grep(/^[a-zA-Z-]+:.+$/)
129
- assert_equal(headers.count, headers.uniq.count)
130
- thread.kill
131
- thread.join
132
- end
133
- end
134
-
135
- def test_sends_valid_version_header
136
- stub_request(:get, 'http://some-host-3/')
137
- .with(headers: { 'X-Zold-Version' => Zold::VERSION })
138
- .to_return(status: 200)
139
- res = Zold::Http.new(uri: 'http://some-host-3/').get
140
- assert_equal(200, res.status, res)
141
- end
142
-
143
- def test_uploads_file
144
- WebMock.allow_net_connect!
145
- RandomPort::Pool::SINGLETON.acquire do |port|
146
- latch = Concurrent::CountDownLatch.new(1)
147
- thread = Thread.start do
148
- Zold::VerboseThread.new(fake_log).run do
149
- server = TCPServer.new(port)
150
- latch.count_down
151
- socket = server.accept
152
- body = ''
153
- stops = 0
154
- loop do
155
- part = socket.read_nonblock(5, exception: false)
156
- if part == :wait_readable
157
- break if stops > 5
158
- stops += 1
159
- sleep 0.001
160
- else
161
- body += part
162
- stops = 0
163
- end
164
- end
165
- socket.close_read
166
- socket.print("HTTP/1.1 200 OK\nContent-Length: #{body.length}\n\n#{body}")
167
- socket.close_write
168
- end
169
- end
170
- latch.wait
171
- content = "how are you\nmy friend"
172
- res = Tempfile.open do |f|
173
- File.write(f, content)
174
- Zold::Http.new(uri: "http://localhost:#{port}/").put(f)
175
- end
176
- assert_equal(200, res.status, res)
177
- assert_includes(res.body, content, res)
178
- thread.kill
179
- thread.join
180
- end
181
- end
182
-
183
- def test_downloads_file
184
- WebMock.allow_net_connect!
185
- RandomPort::Pool::SINGLETON.acquire do |port|
186
- content = "how are you\nmy friend" * 1000
187
- latch = Concurrent::CountDownLatch.new(1)
188
- thread = Thread.start do
189
- Zold::VerboseThread.new(fake_log).run do
190
- server = TCPServer.new(port)
191
- latch.count_down
192
- socket = server.accept
193
- socket.print("HTTP/1.1 200 OK\nContent-Length: #{content.length}\n\n#{content}")
194
- socket.close_write
195
- end
196
- end
197
- latch.wait
198
- body = Tempfile.open do |f|
199
- Zold::Http.new(uri: "http://localhost:#{port}/").get_file(f)
200
- File.read(f)
201
- end
202
- assert_includes(body, content, body)
203
- thread.kill
204
- thread.join
205
- end
206
- end
207
- end