Commit feef9ebc authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'kerrizor/add-tests-for-blob_truncated' into 'master'

Add tests for Gitlab::Git::Blob#truncated?

See merge request gitlab-org/gitlab!25564
parents d06e6343 e2abf597
...@@ -165,7 +165,9 @@ module Gitlab ...@@ -165,7 +165,9 @@ module Gitlab
end end
def truncated? def truncated?
size && (size > loaded_size) return false unless size && loaded_size
size > loaded_size
end end
# Valid LFS object pointer is a text file consisting of # Valid LFS object pointer is a text file consisting of
......
...@@ -613,6 +613,40 @@ describe Gitlab::Git::Blob, :seed_helper do ...@@ -613,6 +613,40 @@ describe Gitlab::Git::Blob, :seed_helper do
end end
end end
describe '#truncated?' do
context 'when blob.size is nil' do
let(:nil_size_blob) { Gitlab::Git::Blob.new(name: 'test', data: 'abcd') }
it 'returns false' do
expect(nil_size_blob.truncated?).to be_falsey
end
end
context 'when blob.data is missing' do
let(:nil_data_blob) { Gitlab::Git::Blob.new(name: 'test', size: 4) }
it 'returns false' do
expect(nil_data_blob.truncated?).to be_falsey
end
end
context 'when the blob is truncated' do
let(:truncated_blob) { Gitlab::Git::Blob.new(name: 'test', size: 40, data: 'abcd') }
it 'returns true' do
expect(truncated_blob.truncated?).to be_truthy
end
end
context 'when the blob is untruncated' do
let(:untruncated_blob) { Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd') }
it 'returns false' do
expect(untruncated_blob.truncated?).to be_falsey
end
end
end
describe 'metrics' do describe 'metrics' do
it 'defines :gitlab_blob_truncated_true counter' do it 'defines :gitlab_blob_truncated_true counter' do
expect(described_class).to respond_to(:gitlab_blob_truncated_true) expect(described_class).to respond_to(:gitlab_blob_truncated_true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment