baza.rb 0.9.1 → 0.9.3
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 +4 -0
- data/Gemfile.lock +28 -0
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +4 -6
- data/test/test_baza-rb.rb +56 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc6218bb18b7baff1acf3119b775c05a7fc1200d8fe6bea72de26e052be2028
|
4
|
+
data.tar.gz: 4b58db5eda95b13edea4b09a223a3d787a4cbeffc80eb0025b8a16f2ed587fd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a444b7f90eb26e3517e40d01ddcb1654b1ed7e027c397e0892ee01d5be286872910c7124317a187f55ecb9ac6d437d0d7055496cedb52a0a69c59158b3ba447d
|
7
|
+
data.tar.gz: cc40e75452008681775d7428861f161058f1fa6b3127e0d80c84e1a29296e75bb76a3554920614fa42d5393a2bb67d37fb3906376ed63c121f1135f7233d5c46
|
data/Gemfile
CHANGED
@@ -11,7 +11,10 @@ gem 'factbase', '~>0.11', require: false
|
|
11
11
|
gem 'minitest', '~>5.25', require: false
|
12
12
|
gem 'minitest-reporters', '~>1.7', require: false
|
13
13
|
gem 'os', '~>1.1', require: false
|
14
|
+
gem 'puma', '~>6.6', require: false
|
14
15
|
gem 'qbash', '~>0.4', require: false
|
16
|
+
gem 'rack', '~>3.1', require: false
|
17
|
+
gem 'rackup', '~>2.2', require: false
|
15
18
|
gem 'rake', '~>13.2', require: false
|
16
19
|
gem 'random-port', '~>0.7', require: false
|
17
20
|
gem 'rubocop', '~>1.73', require: false
|
@@ -20,6 +23,7 @@ gem 'rubocop-performance', '~>1.23', require: false
|
|
20
23
|
gem 'rubocop-rake', '~>0.7', require: false
|
21
24
|
gem 'simplecov', '~>0.22', require: false
|
22
25
|
gem 'simplecov-cobertura', '~>2.1', require: false
|
26
|
+
gem 'sinatra', '~>4.1', require: false
|
23
27
|
gem 'wait_for', '~>0.1', require: false
|
24
28
|
gem 'webmock', '~>3.24', require: false
|
25
29
|
gem 'webrick', '~>1.9', require: false
|
data/Gemfile.lock
CHANGED
@@ -76,8 +76,11 @@ GEM
|
|
76
76
|
minitest (>= 5.0)
|
77
77
|
ruby-progressbar
|
78
78
|
multipart-post (2.4.1)
|
79
|
+
mustermann (3.0.3)
|
80
|
+
ruby2_keywords (~> 0.0.1)
|
79
81
|
net-http (0.6.0)
|
80
82
|
uri
|
83
|
+
nio4r (2.7.4)
|
81
84
|
nokogiri (1.18.8-arm64-darwin)
|
82
85
|
racc (~> 1.4)
|
83
86
|
nokogiri (1.18.8-x64-mingw-ucrt)
|
@@ -94,12 +97,24 @@ GEM
|
|
94
97
|
racc
|
95
98
|
prism (1.4.0)
|
96
99
|
public_suffix (6.0.2)
|
100
|
+
puma (6.6.0)
|
101
|
+
nio4r (~> 2.0)
|
97
102
|
qbash (0.4.5)
|
98
103
|
backtrace (> 0)
|
99
104
|
elapsed (> 0)
|
100
105
|
loog (> 0)
|
101
106
|
tago (> 0)
|
102
107
|
racc (1.8.1)
|
108
|
+
rack (3.1.16)
|
109
|
+
rack-protection (4.1.1)
|
110
|
+
base64 (>= 0.1.0)
|
111
|
+
logger (>= 1.6.0)
|
112
|
+
rack (>= 3.0.0, < 4)
|
113
|
+
rack-session (2.1.1)
|
114
|
+
base64 (>= 0.1.0)
|
115
|
+
rack (>= 3.0.0)
|
116
|
+
rackup (2.2.1)
|
117
|
+
rack (>= 3)
|
103
118
|
rainbow (3.1.1)
|
104
119
|
rake (13.3.0)
|
105
120
|
random-port (0.7.5)
|
@@ -133,6 +148,7 @@ GEM
|
|
133
148
|
lint_roller (~> 1.1)
|
134
149
|
rubocop (>= 1.72.1)
|
135
150
|
ruby-progressbar (1.13.0)
|
151
|
+
ruby2_keywords (0.0.5)
|
136
152
|
simplecov (0.22.0)
|
137
153
|
docile (~> 1.1)
|
138
154
|
simplecov-html (~> 0.11)
|
@@ -142,7 +158,15 @@ GEM
|
|
142
158
|
simplecov (~> 0.19)
|
143
159
|
simplecov-html (0.13.1)
|
144
160
|
simplecov_json_formatter (0.1.4)
|
161
|
+
sinatra (4.1.1)
|
162
|
+
logger (>= 1.6.0)
|
163
|
+
mustermann (~> 3.0)
|
164
|
+
rack (>= 3.0.0, < 4)
|
165
|
+
rack-protection (= 4.1.1)
|
166
|
+
rack-session (>= 2.0.0, < 3)
|
167
|
+
tilt (~> 2.0)
|
145
168
|
tago (0.1.0)
|
169
|
+
tilt (2.6.0)
|
146
170
|
typhoeus (1.4.1)
|
147
171
|
ethon (>= 0.9.0)
|
148
172
|
unicode-display_width (3.1.4)
|
@@ -174,7 +198,10 @@ DEPENDENCIES
|
|
174
198
|
minitest (~> 5.25)
|
175
199
|
minitest-reporters (~> 1.7)
|
176
200
|
os (~> 1.1)
|
201
|
+
puma (~> 6.6)
|
177
202
|
qbash (~> 0.4)
|
203
|
+
rack (~> 3.1)
|
204
|
+
rackup (~> 2.2)
|
178
205
|
rake (~> 13.2)
|
179
206
|
random-port (~> 0.7)
|
180
207
|
rubocop (~> 1.73)
|
@@ -183,6 +210,7 @@ DEPENDENCIES
|
|
183
210
|
rubocop-rake (~> 0.7)
|
184
211
|
simplecov (~> 0.22)
|
185
212
|
simplecov-cobertura (~> 2.1)
|
213
|
+
sinatra (~> 4.1)
|
186
214
|
wait_for (~> 0.1)
|
187
215
|
webmock (~> 3.24)
|
188
216
|
webrick (~> 1.9)
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -732,24 +732,24 @@ class BazaRb
|
|
732
732
|
def download(uri, file)
|
733
733
|
FileUtils.mkdir_p(File.dirname(file))
|
734
734
|
FileUtils.rm_f(file)
|
735
|
+
FileUtils.touch(file)
|
735
736
|
chunk = 0
|
736
737
|
elapsed(@loog) do
|
737
|
-
pos = 0
|
738
738
|
loop do
|
739
739
|
request = Typhoeus::Request.new(
|
740
740
|
uri.to_s,
|
741
741
|
method: :get,
|
742
742
|
headers: headers.merge(
|
743
|
-
'Accept' => '
|
743
|
+
'Accept' => '*',
|
744
744
|
'Accept-Encoding' => 'gzip',
|
745
|
-
'Range' => "bytes=#{
|
745
|
+
'Range' => "bytes=#{File.size(file)}-"
|
746
746
|
),
|
747
747
|
connecttimeout: @timeout,
|
748
748
|
timeout: @timeout
|
749
749
|
)
|
750
750
|
slice = ''
|
751
751
|
request.on_body do |data|
|
752
|
-
slice
|
752
|
+
slice += data
|
753
753
|
end
|
754
754
|
retry_it do
|
755
755
|
request.run
|
@@ -782,8 +782,6 @@ class BazaRb
|
|
782
782
|
_b, e = range.split('-')
|
783
783
|
raise "Range is not valid (#{range.inspect})" unless e.match?(/^[0-9]+$/)
|
784
784
|
len = ret.headers['Content-Length'].to_i
|
785
|
-
pos = e.to_i
|
786
|
-
pos += 1 unless len.zero?
|
787
785
|
break if e.to_i == total.to_i - 1
|
788
786
|
chunk += 1
|
789
787
|
sleep(1) if len.zero?
|
data/test/test_baza-rb.rb
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
require 'factbase'
|
7
7
|
require 'loog'
|
8
8
|
require 'net/http'
|
9
|
+
require 'qbash'
|
9
10
|
require 'random-port'
|
10
11
|
require 'securerandom'
|
11
12
|
require 'socket'
|
@@ -458,7 +459,7 @@ class TestBazaRb < Minitest::Test
|
|
458
459
|
WebMock.disable_net_connect!
|
459
460
|
Dir.mktmpdir do |dir|
|
460
461
|
file = File.join(dir, 'test.txt')
|
461
|
-
File.write(file,
|
462
|
+
File.write(file, "\x00\x00 hi, dude! \x00\xFF\xFE\x12")
|
462
463
|
stub_request(:put, 'https://example.org:443/durables/42')
|
463
464
|
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
464
465
|
.to_return(status: 200)
|
@@ -470,11 +471,12 @@ class TestBazaRb < Minitest::Test
|
|
470
471
|
WebMock.disable_net_connect!
|
471
472
|
Dir.mktmpdir do |dir|
|
472
473
|
file = File.join(dir, 'loaded.txt')
|
474
|
+
data = "\x00\xE0 привет \x00\x00\xFF\xFE\x12"
|
473
475
|
stub_request(:get, 'https://example.org:443/durables/42')
|
474
476
|
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
475
|
-
.to_return(status: 200, body:
|
477
|
+
.to_return(status: 200, body: data, headers: {})
|
476
478
|
fake_baza.durable_load(42, file)
|
477
|
-
assert_equal(
|
479
|
+
assert_equal(data, File.read(file))
|
478
480
|
end
|
479
481
|
end
|
480
482
|
|
@@ -482,13 +484,17 @@ class TestBazaRb < Minitest::Test
|
|
482
484
|
WebMock.disable_net_connect!
|
483
485
|
Dir.mktmpdir do |dir|
|
484
486
|
file = File.join(dir, 'loaded.txt')
|
485
|
-
stub_request(:get, 'https://example.org:443/durables/42')
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
487
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
488
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
489
|
+
.to_return(status: 206, body: '', headers: { 'Content-Range' => 'bytes 0-0/*' })
|
490
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
491
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
492
|
+
.to_return(status: 206, body: 'привет', headers: { 'Content-Range' => 'bytes 0-11/25' })
|
493
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
494
|
+
.with(headers: { 'Range' => 'bytes=12-' })
|
495
|
+
.to_return(status: 206, body: " друг \xFF\xFE\x12", headers: { 'Content-Range' => 'bytes 12-24/25' })
|
490
496
|
fake_baza.durable_load(42, file)
|
491
|
-
assert_equal(
|
497
|
+
assert_equal("привет друг \xFF\xFE\x12", File.read(file))
|
492
498
|
end
|
493
499
|
end
|
494
500
|
|
@@ -674,8 +680,49 @@ class TestBazaRb < Minitest::Test
|
|
674
680
|
baza.push('test', 'data', [])
|
675
681
|
end
|
676
682
|
|
683
|
+
def test_durable_load_from_sinatra
|
684
|
+
WebMock.enable_net_connect!
|
685
|
+
Dir.mktmpdir do |dir|
|
686
|
+
with_sinatra_server do |baza|
|
687
|
+
file = File.join(dir, 'x.txt')
|
688
|
+
baza.durable_load(42, file)
|
689
|
+
assert_equal("Hello, \xFF\xFE\x12!", File.read(file))
|
690
|
+
end
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
677
694
|
private
|
678
695
|
|
696
|
+
def with_sinatra_server
|
697
|
+
Dir.mktmpdir do |dir|
|
698
|
+
app = File.join(dir, 'app.rb')
|
699
|
+
File.write(
|
700
|
+
app,
|
701
|
+
"
|
702
|
+
require 'rack'
|
703
|
+
require 'sinatra'
|
704
|
+
use Rack::Deflater
|
705
|
+
get '/' do
|
706
|
+
'I am alive'
|
707
|
+
end
|
708
|
+
get '/durables/42' do
|
709
|
+
\"Hello, \\xFF\\xFE\\x12!\"
|
710
|
+
end
|
711
|
+
"
|
712
|
+
)
|
713
|
+
RandomPort::Pool::SINGLETON.acquire do |port|
|
714
|
+
host = '127.0.0.1'
|
715
|
+
qbash("bundle exec ruby #{Shellwords.escape(app)} -p #{port}", log: Loog::NULL, accept: nil) do
|
716
|
+
loop do
|
717
|
+
break if Typhoeus::Request.get("http://#{host}:#{port}").code == 200
|
718
|
+
sleep(0.1)
|
719
|
+
end
|
720
|
+
yield BazaRb.new(host, port, '0000-0000-0000', ssl: false)
|
721
|
+
end
|
722
|
+
end
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
679
726
|
def with_http_server(code, response, opts = {})
|
680
727
|
opts = { ssl: false, timeout: 1 }.merge(opts)
|
681
728
|
WebMock.enable_net_connect!
|