fbe 0.22.0 → 0.23.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/Gemfile.lock +7 -3
- data/fbe.gemspec +1 -0
- data/lib/fbe/middleware/sqlite_store.rb +13 -10
- data/lib/fbe/middleware/trace.rb +11 -7
- data/lib/fbe/octo.rb +11 -7
- data/lib/fbe.rb +1 -1
- data/test/fbe/middleware/test_sqlite_store.rb +16 -18
- data/test/fbe/test_octo.rb +56 -25
- data/test/test__helper.rb +4 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afcbfa40757e9ab45bbae7c083105904ebb9079aa821c256c68969c19e3e4e25
|
4
|
+
data.tar.gz: 0416c452b5e217f0fe35ed76676960e751f31229fdca52b5225f7d072c0f5350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fa6f95c316fabbdfe259ef0b49622dbc8480125e3d3c280ef55878148a4b97646d7857f91c447fd592d46a09a59622347e1157c6193d513b820add777abfd78
|
7
|
+
data.tar.gz: 03d2f412f3983ce6e759d40858b2a03d7ba70de2907f6990bcd66d4bc86df77defc65e46e977e9830ba633281c5680a0276a7a8b4a24e59e48c4b33a2efffbe2
|
data/Gemfile.lock
CHANGED
@@ -10,6 +10,7 @@ PATH
|
|
10
10
|
faraday-http-cache (~> 2.5)
|
11
11
|
faraday-multipart (~> 1.1)
|
12
12
|
faraday-retry (~> 2.3)
|
13
|
+
filesize (~> 0.2)
|
13
14
|
graphql-client (~> 0.26)
|
14
15
|
judges (~> 0.46)
|
15
16
|
liquid (~> 5.5)
|
@@ -63,17 +64,19 @@ GEM
|
|
63
64
|
crack (1.0.0)
|
64
65
|
bigdecimal
|
65
66
|
rexml
|
66
|
-
decoor (0.0
|
67
|
+
decoor (0.1.0)
|
67
68
|
docile (1.4.1)
|
68
69
|
drb (2.2.3)
|
69
70
|
elapsed (0.0.1)
|
70
71
|
loog (> 0)
|
71
72
|
tago (> 0)
|
73
|
+
ellipsized (0.3.0)
|
72
74
|
ethon (0.16.0)
|
73
75
|
ffi (>= 1.15.0)
|
74
|
-
factbase (0.11.
|
76
|
+
factbase (0.11.1)
|
75
77
|
backtrace (~> 0.4)
|
76
78
|
decoor (~> 0.0)
|
79
|
+
ellipsized (~> 0.3)
|
77
80
|
json (~> 2.7)
|
78
81
|
logger (~> 1.0)
|
79
82
|
loog (~> 0.6)
|
@@ -98,6 +101,7 @@ GEM
|
|
98
101
|
ffi (1.17.2-x86_64-darwin)
|
99
102
|
ffi (1.17.2-x86_64-linux-gnu)
|
100
103
|
fiber-storage (1.0.1)
|
104
|
+
filesize (0.2.0)
|
101
105
|
gli (2.22.2)
|
102
106
|
ostruct
|
103
107
|
graphql (2.5.9)
|
@@ -112,7 +116,7 @@ GEM
|
|
112
116
|
concurrent-ruby (~> 1.0)
|
113
117
|
iri (0.11.2)
|
114
118
|
json (2.12.2)
|
115
|
-
judges (0.50.
|
119
|
+
judges (0.50.5)
|
116
120
|
backtrace (~> 0.4)
|
117
121
|
baza.rb (~> 0.5)
|
118
122
|
concurrent-ruby (~> 1.2)
|
data/fbe.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_dependency 'faraday-http-cache', '~>2.5'
|
31
31
|
s.add_dependency 'faraday-multipart', '~>1.1'
|
32
32
|
s.add_dependency 'faraday-retry', '~>2.3'
|
33
|
+
s.add_dependency 'filesize', '~>0.2'
|
33
34
|
s.add_dependency 'graphql-client', '~>0.26'
|
34
35
|
s.add_dependency 'judges', '~>0.46'
|
35
36
|
s.add_dependency 'liquid', '~>5.5'
|
@@ -3,10 +3,11 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'filesize'
|
7
7
|
require 'json'
|
8
|
-
require 'sqlite3'
|
9
8
|
require 'loog'
|
9
|
+
require 'sqlite3'
|
10
|
+
require 'time'
|
10
11
|
require_relative '../../fbe'
|
11
12
|
require_relative '../../fbe/middleware'
|
12
13
|
|
@@ -28,9 +29,8 @@ require_relative '../../fbe/middleware'
|
|
28
29
|
# '/path/to/cache.db',
|
29
30
|
# '1.0.0',
|
30
31
|
# loog: logger,
|
31
|
-
# maxsize:
|
32
|
+
# maxsize: '50Mb'
|
32
33
|
# )
|
33
|
-
#
|
34
34
|
# # Use with Faraday
|
35
35
|
# Faraday.new do |builder|
|
36
36
|
# builder.use Faraday::HttpCache, store: store
|
@@ -53,7 +53,7 @@ class Fbe::Middleware::SqliteStore
|
|
53
53
|
# @param maxsize [Integer] Maximum database size in bytes (optional, defaults to 10MB)
|
54
54
|
# @param maxvsize [Integer] Maximum size in bytes of a single value (optional, defaults to 10Kb)
|
55
55
|
# @raise [ArgumentError] If path is nil/empty, directory doesn't exist, or version is nil/empty
|
56
|
-
def initialize(path, version, loog: Loog::NULL, maxsize:
|
56
|
+
def initialize(path, version, loog: Loog::NULL, maxsize: '10Mb', maxvsize: '10Kb')
|
57
57
|
raise ArgumentError, 'Database path cannot be nil or empty' if path.nil? || path.empty?
|
58
58
|
dir = File.dirname(path)
|
59
59
|
raise ArgumentError, "Directory #{dir} does not exist" unless File.directory?(dir)
|
@@ -61,8 +61,8 @@ class Fbe::Middleware::SqliteStore
|
|
61
61
|
@path = File.absolute_path(path)
|
62
62
|
@version = version
|
63
63
|
@loog = loog
|
64
|
-
@maxsize = maxsize
|
65
|
-
@maxvsize = maxvsize
|
64
|
+
@maxsize = Filesize.from(maxsize.to_s).to_i
|
65
|
+
@maxvsize = Filesize.from(maxvsize.to_s).to_i
|
66
66
|
end
|
67
67
|
|
68
68
|
# Read a value from the cache.
|
@@ -161,8 +161,8 @@ class Fbe::Middleware::SqliteStore
|
|
161
161
|
end
|
162
162
|
if File.size(@path) > @maxsize
|
163
163
|
@loog.info(
|
164
|
-
"SQLite cache file size (#{File.size(@path)} bytes) exceeds " \
|
165
|
-
"#{@maxsize
|
164
|
+
"SQLite cache file size (#{Filesize.from(File.size(@path).to_s).pretty} bytes) exceeds " \
|
165
|
+
"#{Filesize.from(@maxsize.to_s).pretty}, cleaning up old entries"
|
166
166
|
)
|
167
167
|
deleted = 0
|
168
168
|
while d.execute(<<~SQL).dig(0, 0) > @maxsize
|
@@ -178,7 +178,10 @@ class Fbe::Middleware::SqliteStore
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
d.execute 'VACUUM;'
|
181
|
-
@loog.info(
|
181
|
+
@loog.info(
|
182
|
+
"Deleted #{deleted} old cache entries, " \
|
183
|
+
"new file size: #{Filesize.from(File.size(@path).to_s).pretty} bytes"
|
184
|
+
)
|
182
185
|
end
|
183
186
|
at_exit { @db&.close }
|
184
187
|
end
|
data/lib/fbe/middleware/trace.rb
CHANGED
@@ -31,9 +31,11 @@ class Fbe::Middleware::Trace < Faraday::Middleware
|
|
31
31
|
#
|
32
32
|
# @param [Object] app The next middleware in the stack
|
33
33
|
# @param [Array] trace The array to store trace entries
|
34
|
-
|
34
|
+
# @param [Boolean] all Print ALL requests, even very fast?
|
35
|
+
def initialize(app, trace, all: true)
|
35
36
|
super(app)
|
36
37
|
@trace = trace
|
38
|
+
@all = all
|
37
39
|
end
|
38
40
|
|
39
41
|
# Processes the HTTP request and records trace information.
|
@@ -41,18 +43,20 @@ class Fbe::Middleware::Trace < Faraday::Middleware
|
|
41
43
|
# @param [Faraday::Env] env The request environment
|
42
44
|
# @return [Faraday::Response] The response from the next middleware
|
43
45
|
def call(env)
|
44
|
-
started = Time.now
|
45
46
|
entry = {
|
46
47
|
method: env.method,
|
47
48
|
url: env.url.to_s,
|
48
|
-
started_at:
|
49
|
+
started_at: Time.now
|
49
50
|
}
|
50
51
|
@app.call(env).on_complete do |response_env|
|
51
52
|
finished = Time.now
|
52
|
-
entry[:
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
duration = finished - entry[:started_at]
|
54
|
+
if duration > 0.01 || @all
|
55
|
+
entry[:status] = response_env.status
|
56
|
+
entry[:finished_at] = finished
|
57
|
+
entry[:duration] = duration
|
58
|
+
@trace << entry
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
data/lib/fbe/octo.rb
CHANGED
@@ -7,6 +7,7 @@ require 'json'
|
|
7
7
|
require 'decoor'
|
8
8
|
require 'faraday/http_cache'
|
9
9
|
require 'faraday/retry'
|
10
|
+
require 'filesize'
|
10
11
|
require 'loog'
|
11
12
|
require 'obk'
|
12
13
|
require 'octokit'
|
@@ -82,13 +83,13 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
82
83
|
backoff_factor: 2
|
83
84
|
)
|
84
85
|
if options.sqlite_cache
|
85
|
-
maxsize = options.sqlite_cache_maxsize ||
|
86
|
-
maxvsize = options.sqlite_cache_maxxsize ||
|
86
|
+
maxsize = Filesize.from(options.sqlite_cache_maxsize || '10M').to_i
|
87
|
+
maxvsize = Filesize.from(options.sqlite_cache_maxxsize || '10K').to_i
|
87
88
|
store = Fbe::Middleware::SqliteStore.new(options.sqlite_cache, Fbe::VERSION, loog:, maxsize:, maxvsize:)
|
88
89
|
loog.info(
|
89
90
|
"Using HTTP cache in SQLite file: #{store.path} (" \
|
90
|
-
"#{File.exist?(store.path) ?
|
91
|
-
"max size: #{maxsize
|
91
|
+
"#{File.exist?(store.path) ? Filesize.from(File.size(store.path).to_s).pretty : 'file is absent'}, " \
|
92
|
+
"max size: #{Filesize.from(maxsize.to_s).pretty}, max vsize: #{Filesize.from(maxvsize.to_s).pretty})"
|
92
93
|
)
|
93
94
|
builder.use(
|
94
95
|
Faraday::HttpCache,
|
@@ -103,7 +104,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
103
104
|
end
|
104
105
|
builder.use(Octokit::Response::RaiseError)
|
105
106
|
builder.use(Faraday::Response::Logger, loog, formatter: Fbe::Middleware::Formatter)
|
106
|
-
builder.use(Fbe::Middleware::Trace, trace)
|
107
|
+
builder.use(Fbe::Middleware::Trace, trace, all: false)
|
107
108
|
builder.adapter(Faraday.default_adapter)
|
108
109
|
end
|
109
110
|
o.middleware = stack
|
@@ -131,9 +132,12 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
131
132
|
end
|
132
133
|
message = grouped
|
133
134
|
.sort_by { |_path, entries| -entries.count }
|
134
|
-
.map { |path, entries| " #{path}: #{entries.count}" }
|
135
|
+
.map { |path, entries| " #{path.gsub(%r{^https://api.github.com/}, '/')}: #{entries.count}" }
|
135
136
|
.join("\n")
|
136
|
-
@loog.info(
|
137
|
+
@loog.info(
|
138
|
+
"GitHub API trace (#{grouped.count} URLs vs #{@trace.count} requests, " \
|
139
|
+
"#{@origin.rate_limit.remaining} quota left):\n#{message}"
|
140
|
+
)
|
137
141
|
@trace.clear
|
138
142
|
end
|
139
143
|
end
|
data/lib/fbe.rb
CHANGED
@@ -33,14 +33,14 @@ class SqliteStoreTest < Fbe::Test
|
|
33
33
|
|
34
34
|
def test_returns_empty_list
|
35
35
|
with_tmpfile('b.db') do |f|
|
36
|
-
store = Fbe::Middleware::SqliteStore.new(f, '0.0.0')
|
36
|
+
store = Fbe::Middleware::SqliteStore.new(f, '0.0.0', loog: fake_loog)
|
37
37
|
assert_empty(store.all)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_clear_all_keys
|
42
42
|
with_tmpfile('a.db') do |f|
|
43
|
-
store = Fbe::Middleware::SqliteStore.new(f, '0.0.0')
|
43
|
+
store = Fbe::Middleware::SqliteStore.new(f, '0.0.0', loog: fake_loog)
|
44
44
|
k = 'a key'
|
45
45
|
store.write(k, 'some value')
|
46
46
|
store.clear
|
@@ -50,20 +50,20 @@ class SqliteStoreTest < Fbe::Test
|
|
50
50
|
|
51
51
|
def test_empty_all_if_not_written
|
52
52
|
with_tmpfile do |f|
|
53
|
-
store = Fbe::Middleware::SqliteStore.new(f, '0.0.0')
|
53
|
+
store = Fbe::Middleware::SqliteStore.new(f, '0.0.0', loog: fake_loog)
|
54
54
|
assert_empty(store.all)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_wrong_db_path
|
59
59
|
assert_raises(ArgumentError) do
|
60
|
-
Fbe::Middleware::SqliteStore.new(nil, '0.0.0').read('my_key')
|
60
|
+
Fbe::Middleware::SqliteStore.new(nil, '0.0.0', loog: fake_loog).read('my_key')
|
61
61
|
end
|
62
62
|
assert_raises(ArgumentError) do
|
63
|
-
Fbe::Middleware::SqliteStore.new('', '0.0.0').read('my_key')
|
63
|
+
Fbe::Middleware::SqliteStore.new('', '0.0.0', loog: fake_loog).read('my_key')
|
64
64
|
end
|
65
65
|
assert_raises(ArgumentError) do
|
66
|
-
Fbe::Middleware::SqliteStore.new('/fakepath/fakefolder/test.db', '0.0.0').read('my_key')
|
66
|
+
Fbe::Middleware::SqliteStore.new('/fakepath/fakefolder/test.db', '0.0.0', loog: fake_loog).read('my_key')
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -72,7 +72,7 @@ class SqliteStoreTest < Fbe::Test
|
|
72
72
|
File.binwrite(f, Array.new(20) { rand(0..255) }.pack('C*'))
|
73
73
|
ex =
|
74
74
|
assert_raises(SQLite3::NotADatabaseException) do
|
75
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.0').read('my_key')
|
75
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.0', loog: fake_loog).read('my_key')
|
76
76
|
end
|
77
77
|
assert_match('file is not a database', ex.message)
|
78
78
|
end
|
@@ -83,7 +83,6 @@ class SqliteStoreTest < Fbe::Test
|
|
83
83
|
require 'tempfile'
|
84
84
|
require 'sqlite3'
|
85
85
|
require 'fbe/middleware/sqlite_store'
|
86
|
-
|
87
86
|
SQLite3::Database.class_eval do
|
88
87
|
prepend(Module.new do
|
89
88
|
def close
|
@@ -92,7 +91,6 @@ class SqliteStoreTest < Fbe::Test
|
|
92
91
|
end
|
93
92
|
end)
|
94
93
|
end
|
95
|
-
|
96
94
|
Tempfile.open('test.db') do |f|
|
97
95
|
Fbe::Middleware::SqliteStore.new(f.path, '0.0.0').then do |s|
|
98
96
|
s.write('my_key', 'my_value')
|
@@ -111,15 +109,15 @@ class SqliteStoreTest < Fbe::Test
|
|
111
109
|
|
112
110
|
def test_different_versions
|
113
111
|
with_tmpfile('d.db') do |f|
|
114
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
112
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1', loog: fake_loog).then do |store|
|
115
113
|
store.write('kkk1', 'some value')
|
116
114
|
store.write('kkk2', 'another value')
|
117
115
|
end
|
118
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
116
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1', loog: fake_loog).then do |store|
|
119
117
|
assert_equal('some value', store.read('kkk1'))
|
120
118
|
assert_equal('another value', store.read('kkk2'))
|
121
119
|
end
|
122
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.2').then do |store|
|
120
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.2', loog: fake_loog).then do |store|
|
123
121
|
assert_nil(store.read('kkk1'))
|
124
122
|
assert_nil(store.read('kkk2'))
|
125
123
|
end
|
@@ -129,10 +127,10 @@ class SqliteStoreTest < Fbe::Test
|
|
129
127
|
def test_initialize_wrong_version
|
130
128
|
with_tmpfile('e.db') do |f|
|
131
129
|
msg = 'Version cannot be nil or empty'
|
132
|
-
assert_raises(ArgumentError) { Fbe::Middleware::SqliteStore.new(f, nil) }.then do |ex|
|
130
|
+
assert_raises(ArgumentError) { Fbe::Middleware::SqliteStore.new(f, nil, loog: fake_loog) }.then do |ex|
|
133
131
|
assert_match(msg, ex.message)
|
134
132
|
end
|
135
|
-
assert_raises(ArgumentError) { Fbe::Middleware::SqliteStore.new(f, '') }.then do |ex|
|
133
|
+
assert_raises(ArgumentError) { Fbe::Middleware::SqliteStore.new(f, '', loog: fake_loog) }.then do |ex|
|
136
134
|
assert_match(msg, ex.message)
|
137
135
|
end
|
138
136
|
end
|
@@ -140,7 +138,7 @@ class SqliteStoreTest < Fbe::Test
|
|
140
138
|
|
141
139
|
def test_skip_write_if_value_more_then_10k_bytes
|
142
140
|
with_tmpfile('a.db') do |f|
|
143
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
141
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1', loog: fake_loog).then do |store|
|
144
142
|
store.write('a', 'a' * 9_997)
|
145
143
|
store.write('b', 'b' * 9_998)
|
146
144
|
store.write('c', 'c' * 19_999)
|
@@ -155,7 +153,7 @@ class SqliteStoreTest < Fbe::Test
|
|
155
153
|
|
156
154
|
def test_shrink_cache_if_more_then_10_mb
|
157
155
|
with_tmpfile('large.db') do |f|
|
158
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
156
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1', loog: fake_loog).then do |store|
|
159
157
|
key = 'aaa'
|
160
158
|
alpha = ('a'..'z').to_a
|
161
159
|
store.write('a', 'aa')
|
@@ -173,7 +171,7 @@ class SqliteStoreTest < Fbe::Test
|
|
173
171
|
end
|
174
172
|
end
|
175
173
|
assert_operator(File.size(f), :>, 10 * 1024 * 1024)
|
176
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
174
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1', loog: fake_loog).then do |store|
|
177
175
|
assert_equal('aa', store.read('a'))
|
178
176
|
assert_nil(store.read('b'))
|
179
177
|
assert_equal('cc', store.read('c'))
|
@@ -193,7 +191,7 @@ class SqliteStoreTest < Fbe::Test
|
|
193
191
|
d.execute 'CREATE TABLE IF NOT EXISTS meta(key TEXT UNIQUE NOT NULL, value TEXT);'
|
194
192
|
d.execute "INSERT INTO meta(key, value) VALUES('version', ?);", ['0.0.1']
|
195
193
|
end
|
196
|
-
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
194
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1', loog: fake_loog).then do |store|
|
197
195
|
assert_equal('value1', store.read('key1'))
|
198
196
|
assert_equal('value2', store.read('key2'))
|
199
197
|
rescue SQLite3::SQLException => e
|
data/test/fbe/test_octo.rb
CHANGED
@@ -366,30 +366,66 @@ class TestOcto < Fbe::Test
|
|
366
366
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
367
367
|
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
368
368
|
)
|
369
|
-
stub_request(:get, 'https://api.github.com/user/123').to_return
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
369
|
+
stub_request(:get, 'https://api.github.com/user/123').to_return do
|
370
|
+
sleep(0.02)
|
371
|
+
{
|
372
|
+
status: 200,
|
373
|
+
body: '{"id":123,"login":"test"}',
|
374
|
+
headers: { 'X-RateLimit-Remaining' => '222' }
|
375
|
+
}
|
376
|
+
end
|
377
|
+
stub_request(:get, 'https://api.github.com/repos/foo/bar').to_return do
|
378
|
+
sleep(0.02)
|
379
|
+
{
|
380
|
+
status: 200,
|
381
|
+
body: '{"id":456,"full_name":"foo/bar"}',
|
382
|
+
headers: { 'X-RateLimit-Remaining' => '222' }
|
383
|
+
}
|
384
|
+
end
|
379
385
|
octo = Fbe.octo(loog:, global: {}, options: Judges::Options.new)
|
380
386
|
octo.user(123)
|
381
387
|
octo.repository('foo/bar')
|
382
388
|
octo.repository('foo/bar')
|
383
389
|
octo.print_trace!
|
384
390
|
output = loog.to_s
|
385
|
-
assert_includes output, '
|
386
|
-
assert_includes output, '
|
387
|
-
assert_includes output, '
|
388
|
-
|
389
|
-
|
391
|
+
assert_includes output, '2 URLs vs 3 requests'
|
392
|
+
assert_includes output, '222 quota left'
|
393
|
+
assert_includes output, '/user/123: 1'
|
394
|
+
assert_includes output, '/repos/foo/bar: 2'
|
395
|
+
repo_index = output.index('/repos/foo/bar: 2')
|
396
|
+
user_index = output.index('/user/123: 1')
|
390
397
|
assert_operator repo_index, :<, user_index, 'URLs should be sorted by request count (highest first)'
|
391
398
|
end
|
392
399
|
|
400
|
+
def test_prints_only_real_requests
|
401
|
+
WebMock.disable_net_connect!
|
402
|
+
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
403
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
404
|
+
)
|
405
|
+
stub = stub_request(:get, 'https://api.github.com/user/123').to_return(
|
406
|
+
status: 200,
|
407
|
+
body: '{"id":123,"login":"test"}',
|
408
|
+
headers: {
|
409
|
+
'X-RateLimit-Remaining' => '222',
|
410
|
+
'Content-Type' => 'application/json',
|
411
|
+
'Cache-Control' => 'public, max-age=60, s-maxage=60',
|
412
|
+
'Etag' => 'W/"2ff9dd4c3153f006830b2b8b721f6a4bb400a1eb81a2e1fa0a3b846ad349b9ec"',
|
413
|
+
'Last-Modified' => 'Wed, 01 May 2025 20:00:00 GMT'
|
414
|
+
}
|
415
|
+
)
|
416
|
+
Dir.mktmpdir do |dir|
|
417
|
+
fcache = File.expand_path('test.db', dir)
|
418
|
+
octo = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'sqlite_cache' => fcache }))
|
419
|
+
octo.user(123)
|
420
|
+
loog = Loog::Buffer.new
|
421
|
+
octo = Fbe.octo(loog: fake_loog, global: {}, options: Judges::Options.new({ 'sqlite_cache' => fcache }))
|
422
|
+
WebMock.remove_request_stub(stub)
|
423
|
+
octo.user(123)
|
424
|
+
octo.print_trace!
|
425
|
+
assert_empty(loog.to_s)
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
393
429
|
def test_trace_gets_cleared_after_print
|
394
430
|
WebMock.disable_net_connect!
|
395
431
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
@@ -414,9 +450,8 @@ class TestOcto < Fbe::Test
|
|
414
450
|
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
415
451
|
)
|
416
452
|
Dir.mktmpdir do |dir|
|
417
|
-
global = {}
|
418
453
|
sqlite_cache = File.expand_path('test.db', dir)
|
419
|
-
o = Fbe.octo(loog: Loog::NULL, global
|
454
|
+
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'sqlite_cache' => sqlite_cache }))
|
420
455
|
stub = stub_request(:get, 'https://api.github.com/user/42').to_return(
|
421
456
|
status: 200,
|
422
457
|
body: { login: 'user1' }.to_json,
|
@@ -429,8 +464,7 @@ class TestOcto < Fbe::Test
|
|
429
464
|
)
|
430
465
|
assert_equal('user1', o.user_name_by_id(42))
|
431
466
|
WebMock.remove_request_stub(stub)
|
432
|
-
|
433
|
-
o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new({ 'sqlite_cache' => sqlite_cache }))
|
467
|
+
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'sqlite_cache' => sqlite_cache }))
|
434
468
|
assert_equal('user1', o.user_name_by_id(42))
|
435
469
|
end
|
436
470
|
end
|
@@ -441,10 +475,9 @@ class TestOcto < Fbe::Test
|
|
441
475
|
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
442
476
|
)
|
443
477
|
Dir.mktmpdir do |dir|
|
444
|
-
global = {}
|
445
478
|
file = File.expand_path('test.db', dir)
|
446
479
|
stub_request(:get, 'https://api.github.com/user/4242').to_return(status: 401)
|
447
|
-
o = Fbe.octo(loog: Loog::NULL, global
|
480
|
+
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'sqlite_cache' => file }))
|
448
481
|
assert_raises(StandardError) do
|
449
482
|
assert_equal('user1', o.user_name_by_id(4242))
|
450
483
|
end
|
@@ -458,7 +491,6 @@ class TestOcto < Fbe::Test
|
|
458
491
|
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
459
492
|
)
|
460
493
|
Dir.mktmpdir do |dir|
|
461
|
-
global = {}
|
462
494
|
stub =
|
463
495
|
stub_request(:get, 'https://api.github.com/user/42')
|
464
496
|
.to_return(
|
@@ -473,7 +505,7 @@ class TestOcto < Fbe::Test
|
|
473
505
|
)
|
474
506
|
sqlite_cache = File.expand_path('test.db', dir)
|
475
507
|
Fbe.stub_const(:VERSION, '0.0.1') do
|
476
|
-
o = Fbe.octo(loog: Loog::NULL, global
|
508
|
+
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'sqlite_cache' => sqlite_cache }))
|
477
509
|
assert_equal('user1', o.user_name_by_id(42))
|
478
510
|
end
|
479
511
|
WebMock.remove_request_stub(stub)
|
@@ -488,9 +520,8 @@ class TestOcto < Fbe::Test
|
|
488
520
|
'Last-Modified' => 'Wed, 01 May 2025 20:00:00 GMT'
|
489
521
|
}
|
490
522
|
)
|
491
|
-
global = {}
|
492
523
|
Fbe.stub_const(:VERSION, '0.0.2') do
|
493
|
-
o = Fbe.octo(loog: Loog::NULL, global
|
524
|
+
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'sqlite_cache' => sqlite_cache }))
|
494
525
|
assert_equal('user2', o.user_name_by_id(42))
|
495
526
|
end
|
496
527
|
end
|
data/test/test__helper.rb
CHANGED
@@ -31,6 +31,7 @@ end
|
|
31
31
|
require 'minitest/reporters'
|
32
32
|
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
33
33
|
|
34
|
+
require 'loog'
|
34
35
|
require 'minitest/stub_const'
|
35
36
|
require 'minitest/autorun'
|
36
37
|
require 'webmock/minitest'
|
@@ -38,4 +39,7 @@ require_relative '../lib/fbe'
|
|
38
39
|
|
39
40
|
# Parent class for all tests.
|
40
41
|
class Fbe::Test < Minitest::Test
|
42
|
+
def fake_loog
|
43
|
+
Loog::NULL
|
44
|
+
end
|
41
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -121,6 +121,20 @@ dependencies:
|
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '2.3'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: filesize
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.2'
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.2'
|
124
138
|
- !ruby/object:Gem::Dependency
|
125
139
|
name: graphql-client
|
126
140
|
requirement: !ruby/object:Gem::Requirement
|