baza.rb 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 014c248d64a458634ae5e0230dbffb3efe583b3290ba939b8dce3ed1f91f502b
4
- data.tar.gz: 735858245c3ab0bf9d362d325a47e5304813a3b281e4cc78cafaf6ee066086cb
3
+ metadata.gz: 0ac6dd23ce75d129ed2569730f17c38477220e4637736acf630b3a5b1233e30a
4
+ data.tar.gz: 86036e407483b556df491bc25b9b37ba7a39fd054ec8d5005f7d5f5ef5af1139
5
5
  SHA512:
6
- metadata.gz: da30b50601a6354138e593fffc3680cd2648b6c7b9eeb62d949301ef72e89c9446643f9b15dbca0b252d4e062af8a4b63f5ab3b71cf1ab2abad632427c7f7254
7
- data.tar.gz: 3b394b41273005c73431ca4e191e6f3a653db0498504d59422ef5dacb4d8b8bc59d5cc4ee8c890a79cd2d05100109e8e6151e9f82686ede138bb0f00109bb0bd
6
+ metadata.gz: abc122fe9f3500aee61644f9605fdd11b5d4afbf593ccbcf000be18802799a144573822aa51aa88fe3b84140a0dd2be9d04001a5cdbb5c9e00d7cf28e6f39e00
7
+ data.tar.gz: 85d8540811e627ee942821862da29b2578d92362dd889d9f12c85f8713377cd30151213449ee079d63702d2bf47d927de1892b49755ee28407cf13f569ca82ab
data/.rubocop.yml CHANGED
@@ -62,3 +62,5 @@ Metrics/ParameterLists:
62
62
  Enabled: false
63
63
  Layout/MultilineAssignmentLayout:
64
64
  Enabled: true
65
+ Naming/FileName:
66
+ Enabled: false
data/.rultor.yml CHANGED
@@ -31,8 +31,8 @@ release:
31
31
  [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
32
32
  bundle exec rake
33
33
  rm -rf *.gem
34
- sed -i "s/0\.0\.0/${tag}/g" lib/baza/version.rb
35
- git add lib/baza/version.rb
34
+ sed -i "s/0\.0\.0/${tag}/g" lib/baza-rb/version.rb
35
+ git add lib/baza-rb/version.rb
36
36
  git commit -m "version set to ${tag}"
37
37
  gem build baza.rb.gemspec
38
38
  chmod 0600 ../rubygems.yml
data/Gemfile CHANGED
@@ -35,5 +35,6 @@ gem 'rubocop-performance', '1.21.1', require: false
35
35
  gem 'rubocop-rspec', '3.0.4', require: false
36
36
  gem 'simplecov', '0.22.0', require: false
37
37
  gem 'simplecov-cobertura', '2.1.0', require: false
38
+ gem 'wait_for', '~>0', require: false
38
39
  gem 'webmock', '3.23.1', require: false
39
40
  gem 'yard', '0.9.36', require: false
data/Gemfile.lock CHANGED
@@ -222,6 +222,7 @@ GEM
222
222
  unicode-display_width (2.5.0)
223
223
  uri (0.13.0)
224
224
  useragent (0.16.10)
225
+ wait_for (0.1.1)
225
226
  webmock (3.23.1)
226
227
  addressable (>= 2.8.0)
227
228
  crack (>= 0.3.2)
@@ -252,6 +253,7 @@ DEPENDENCIES
252
253
  rubocop-rspec (= 3.0.4)
253
254
  simplecov (= 0.22.0)
254
255
  simplecov-cobertura (= 2.1.0)
256
+ wait_for (~> 0)
255
257
  webmock (= 3.23.1)
256
258
  yard (= 0.9.36)
257
259
 
data/baza.rb.gemspec CHANGED
@@ -21,13 +21,13 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'English'
24
- require_relative 'lib/baza/version'
24
+ require_relative 'lib/baza-rb/version'
25
25
 
26
26
  Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
28
  s.required_ruby_version = '>=3.0'
29
29
  s.name = 'baza.rb'
30
- s.version = Baza::VERSION
30
+ s.version = BazaRb::VERSION
31
31
  s.license = 'MIT'
32
32
  s.summary = 'Zerocracy API Ruby Client'
33
33
  s.description =
@@ -25,6 +25,6 @@
25
25
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
26
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
27
27
  # License:: MIT
28
- class Baza
29
- VERSION = '0.0.2'
28
+ class BazaRb
29
+ VERSION = '0.0.4'
30
30
  end
@@ -20,13 +20,13 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require 'typhoeus'
24
- require 'retries'
23
+ require 'base64'
25
24
  require 'iri'
26
25
  require 'loog'
27
- require 'base64'
26
+ require 'retries'
28
27
  require 'tago'
29
- require_relative 'baza/version'
28
+ require 'typhoeus'
29
+ require_relative 'baza-rb/version'
30
30
 
31
31
  # Interface to the API of zerocracy.com.
32
32
  #
@@ -37,7 +37,7 @@ require_relative 'baza/version'
37
37
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
38
38
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
39
39
  # License:: MIT
40
- class Baza
40
+ class BazaRb
41
41
  def initialize(host, port, token, ssl: true, timeout: 30, retries: 3, loog: Loog::NULL, compression: true)
42
42
  @host = host
43
43
  @port = port
@@ -262,6 +262,7 @@ class Baza
262
262
  # @param [String] jname The name of the job on the server
263
263
  # @param [String] file The file name
264
264
  def durable_place(jname, file)
265
+ raise "File '#{file}' is absent" unless File.exist?(file)
265
266
  id = nil
266
267
  elapsed(@loog) do
267
268
  ret =
@@ -272,7 +273,7 @@ class Baza
272
273
  body: {
273
274
  'jname' => jname,
274
275
  'file' => File.basename(file),
275
- 'zip' => File.open(file, 'r')
276
+ 'zip' => File.open(file, 'rb')
276
277
  },
277
278
  headers:,
278
279
  connecttimeout: @timeout,
@@ -291,6 +292,7 @@ class Baza
291
292
  # @param [Integer] id The ID of the durable
292
293
  # @param [String] file The file to upload
293
294
  def durable_save(id, file)
295
+ raise "File '#{file}' is absent" unless File.exist?(file)
294
296
  elapsed(@loog) do
295
297
  with_retries(max_tries: @retries) do
296
298
  checked(
@@ -311,6 +313,7 @@ class Baza
311
313
  # @param [Integer] id The ID of the durable
312
314
  # @param [String] file The file to upload
313
315
  def durable_load(id, file)
316
+ FileUtils.mkdir_p(File.dirname(file))
314
317
  elapsed(@loog) do
315
318
  File.open(file, 'wb') do |f|
316
319
  request = Typhoeus::Request.new(
@@ -374,7 +377,7 @@ class Baza
374
377
 
375
378
  def headers
376
379
  {
377
- 'User-Agent' => "baza.rb #{Baza::VERSION}",
380
+ 'User-Agent' => "baza.rb #{BazaRb::VERSION}",
378
381
  'Connection' => 'close',
379
382
  'X-Zerocracy-Token' => @token
380
383
  }
@@ -431,10 +434,11 @@ class Baza
431
434
  return ret
432
435
  end
433
436
  @loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}")
437
+ headers = ret.headers || {}
434
438
  msg = [
435
439
  "Invalid response code ##{ret.code} ",
436
440
  "at #{mtd} #{url}",
437
- ret.headers['X-Zerocracy-Flash'] ? " (#{ret.headers['X-Zerocracy-Flash'].inspect})" : ''
441
+ headers['X-Zerocracy-Flash'] ? " (#{headers['X-Zerocracy-Flash'].inspect})" : ''
438
442
  ].join
439
443
  case ret.code
440
444
  when 500
@@ -443,7 +447,7 @@ class Baza
443
447
  'please report this to https://github.com/zerocracy/baza'
444
448
  when 503
445
449
  msg +=
446
- ", most probably it's an internal error on the server (#{ret.headers['X-Zerocracy-Failure'].inspect}), " \
450
+ ", most probably it's an internal error on the server (#{headers['X-Zerocracy-Failure'].inspect}), " \
447
451
  'please report this to https://github.com/zerocracy/baza.rb'
448
452
  when 404
449
453
  msg +=
@@ -20,39 +20,28 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require 'minitest/autorun'
24
- require 'webmock/minitest'
25
- require 'webrick'
23
+ require 'factbase'
26
24
  require 'loog'
27
- require 'socket'
28
- require 'stringio'
25
+ require 'minitest/autorun'
26
+ require 'net/ping'
29
27
  require 'random-port'
30
- require 'factbase'
31
28
  require 'securerandom'
32
- require 'net/ping'
33
- require_relative '../lib/baza'
29
+ require 'socket'
30
+ require 'stringio'
31
+ require 'wait_for'
32
+ require 'webmock/minitest'
33
+ require 'webrick'
34
+ require_relative '../lib/baza-rb'
34
35
 
35
36
  # Test.
36
37
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
37
38
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
38
39
  # License:: MIT
39
- class TestBaza < Minitest::Test
40
+ class TestBazaRb < Minitest::Test
40
41
  TOKEN = '00000000-0000-0000-0000-000000000000'
41
42
  HOST = 'api.zerocracy.com'
42
43
  PORT = 443
43
- LIVE = Baza.new(HOST, PORT, TOKEN, loog: Loog::VERBOSE)
44
-
45
- def test_live_recent_check
46
- WebMock.enable_net_connect!
47
- skip unless we_are_online
48
- assert(LIVE.recent('zerocracy').positive?)
49
- end
50
-
51
- def test_live_name_exists_check
52
- WebMock.enable_net_connect!
53
- skip unless we_are_online
54
- assert(LIVE.name_exists?('zerocracy'))
55
- end
44
+ LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::VERBOSE)
56
45
 
57
46
  def test_live_push
58
47
  WebMock.enable_net_connect!
@@ -60,7 +49,18 @@ class TestBaza < Minitest::Test
60
49
  fb = Factbase.new
61
50
  fb.insert.foo = 'test-' * 10_000
62
51
  fb.insert
63
- assert(LIVE.push(fake_name, fb.export, []).positive?)
52
+ n = fake_name
53
+ assert(LIVE.push(n, fb.export, []).positive?)
54
+ assert(LIVE.name_exists?(n))
55
+ assert(LIVE.recent(n).positive?)
56
+ id = LIVE.recent(n)
57
+ wait_for(60) { LIVE.finished?(id) }
58
+ assert(!LIVE.pull(id).nil?)
59
+ assert(!LIVE.stdout(id).nil?)
60
+ assert(!LIVE.exit_code(id).nil?)
61
+ owner = 'baza.rb testing'
62
+ assert(!LIVE.lock(n, owner).nil?)
63
+ assert(!LIVE.unlock(n, owner).nil?)
64
64
  end
65
65
 
66
66
  def test_live_push_no_compression
@@ -69,55 +69,18 @@ class TestBaza < Minitest::Test
69
69
  fb = Factbase.new
70
70
  fb.insert.foo = 'test-' * 10_000
71
71
  fb.insert
72
- baza = Baza.new(HOST, PORT, TOKEN, compression: false)
72
+ baza = BazaRb.new(HOST, PORT, TOKEN, compression: false)
73
73
  assert(baza.push(fake_name, fb.export, []).positive?)
74
74
  end
75
75
 
76
- def test_live_pull
77
- WebMock.enable_net_connect!
78
- skip unless we_are_online
79
- id = LIVE.recent('zerocracy')
80
- assert(!LIVE.pull(id).nil?)
81
- end
82
-
83
- def test_live_check_finished
84
- WebMock.enable_net_connect!
85
- skip unless we_are_online
86
- id = LIVE.recent('zerocracy')
87
- assert(!LIVE.finished?(id).nil?)
88
- end
89
-
90
- def test_live_read_stdout
91
- WebMock.enable_net_connect!
92
- skip unless we_are_online
93
- id = LIVE.recent('zerocracy')
94
- assert(!LIVE.stdout(id).nil?)
95
- end
96
-
97
- def test_live_read_exit_code
98
- WebMock.enable_net_connect!
99
- skip unless we_are_online
100
- id = LIVE.recent('zerocracy')
101
- assert(!LIVE.exit_code(id).nil?)
102
- end
103
-
104
- def test_live_lock_unlock
105
- WebMock.enable_net_connect!
106
- skip unless we_are_online
107
- n = fake_name
108
- owner = 'judges teesting'
109
- assert(!LIVE.lock(n, owner).nil?)
110
- assert(!LIVE.unlock(n, owner).nil?)
111
- end
112
-
113
76
  def test_live_durable_lock_unlock
114
77
  WebMock.enable_net_connect!
115
78
  skip unless we_are_online
116
79
  Dir.mktmpdir do |dir|
117
- file = File.join(dir, 'test.bin')
80
+ file = File.join(dir, "#{fake_name}.bin")
118
81
  File.binwrite(file, 'hello')
119
82
  id = LIVE.durable_place(fake_name, file)
120
- owner = 'judges teesting'
83
+ owner = fake_name
121
84
  LIVE.durable_lock(id, owner)
122
85
  LIVE.durable_load(id, file)
123
86
  LIVE.durable_save(id, file)
@@ -133,7 +96,7 @@ class TestBaza < Minitest::Test
133
96
  Dir.mktmpdir do |dir|
134
97
  file = File.join(dir, 'test.bin')
135
98
  File.binwrite(file, 'hello')
136
- assert_equal(42, Baza.new('example.org', 443, '000').durable_place('simple', file))
99
+ assert_equal(42, BazaRb.new('example.org', 443, '000').durable_place('simple', file))
137
100
  end
138
101
  end
139
102
 
@@ -144,7 +107,7 @@ class TestBaza < Minitest::Test
144
107
  )
145
108
  assert_equal(
146
109
  42,
147
- Baza.new('example.org', 443, '000').push('simple', 'hello, world!', [])
110
+ BazaRb.new('example.org', 443, '000').push('simple', 'hello, world!', [])
148
111
  )
149
112
  end
150
113
 
@@ -155,7 +118,7 @@ class TestBaza < Minitest::Test
155
118
  .to_return(status: 200, body: '42')
156
119
  assert_equal(
157
120
  42,
158
- Baza.new('example.org', 443, '000').recent('simple')
121
+ BazaRb.new('example.org', 443, '000').recent('simple')
159
122
  )
160
123
  end
161
124
 
@@ -165,7 +128,7 @@ class TestBaza < Minitest::Test
165
128
  status: 200, body: 'yes'
166
129
  )
167
130
  assert(
168
- Baza.new('example.org', 443, '000').name_exists?('simple')
131
+ BazaRb.new('example.org', 443, '000').name_exists?('simple')
169
132
  )
170
133
  end
171
134
 
@@ -175,7 +138,7 @@ class TestBaza < Minitest::Test
175
138
  status: 200, body: '0'
176
139
  )
177
140
  assert(
178
- Baza.new('example.org', 443, '000').exit_code(42).zero?
141
+ BazaRb.new('example.org', 443, '000').exit_code(42).zero?
179
142
  )
180
143
  end
181
144
 
@@ -185,7 +148,7 @@ class TestBaza < Minitest::Test
185
148
  status: 200, body: 'hello!'
186
149
  )
187
150
  assert(
188
- !Baza.new('example.org', 443, '000').stdout(42).empty?
151
+ !BazaRb.new('example.org', 443, '000').stdout(42).empty?
189
152
  )
190
153
  end
191
154
 
@@ -195,7 +158,7 @@ class TestBaza < Minitest::Test
195
158
  status: 200, body: 'hello, world!'
196
159
  )
197
160
  assert(
198
- Baza.new('example.org', 443, '000').pull(333).start_with?('hello')
161
+ BazaRb.new('example.org', 443, '000').pull(333).start_with?('hello')
199
162
  )
200
163
  end
201
164
 
@@ -204,7 +167,7 @@ class TestBaza < Minitest::Test
204
167
  with_http_server(200, 'yes') do |baza|
205
168
  baza.name_exists?('simple')
206
169
  end
207
- assert_equal("baza.rb #{Baza::VERSION}", req['user-agent'])
170
+ assert_equal("baza.rb #{BazaRb::VERSION}", req['user-agent'])
208
171
  end
209
172
 
210
173
  def test_push_with_meta
@@ -269,7 +232,7 @@ class TestBaza < Minitest::Test
269
232
  socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
270
233
  socket.close
271
234
  end
272
- yield Baza.new(host, port, '0000', **opts)
235
+ yield BazaRb.new(host, port, '0000', **opts)
273
236
  t.join
274
237
  end
275
238
  req
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-10 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -182,11 +182,11 @@ files:
182
182
  - README.md
183
183
  - Rakefile
184
184
  - baza.rb.gemspec
185
- - lib/baza.rb
186
- - lib/baza/version.rb
185
+ - lib/baza-rb.rb
186
+ - lib/baza-rb/version.rb
187
187
  - renovate.json
188
188
  - test/test__helper.rb
189
- - test/test_baza.rb
189
+ - test/test_baza-rb.rb
190
190
  homepage: http://github.com/zerocracy/baza.rb
191
191
  licenses:
192
192
  - MIT