summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/diff_collection_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-09 21:06:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-09 21:06:24 +0000
commit4b28d5ae770c6bd332283a3f13ceae06329c409b (patch)
treeae4d46e1d017002935fe75dc14cb3c108be12fae /spec/lib/gitlab/git/diff_collection_spec.rb
parent41efffa17c67405ca5f5dac49d72be7872cee339 (diff)
downloadgitlab-ce-4b28d5ae770c6bd332283a3f13ceae06329c409b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/git/diff_collection_spec.rb')
-rw-r--r--spec/lib/gitlab/git/diff_collection_spec.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/diff_collection_spec.rb b/spec/lib/gitlab/git/diff_collection_spec.rb
index be6ab0c1200..ded173c49ef 100644
--- a/spec/lib/gitlab/git/diff_collection_spec.rb
+++ b/spec/lib/gitlab/git/diff_collection_spec.rb
@@ -537,6 +537,70 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
end
end
end
+
+ context 'when offset_index is given' do
+ subject do
+ Gitlab::Git::DiffCollection.new(
+ iterator,
+ max_files: max_files,
+ max_lines: max_lines,
+ limits: limits,
+ offset_index: 2,
+ expanded: expanded
+ )
+ end
+
+ def diff(raw)
+ raw['diff']
+ end
+
+ let(:iterator) do
+ [
+ fake_diff(1, 1),
+ fake_diff(2, 2),
+ fake_diff(3, 3),
+ fake_diff(4, 4)
+ ]
+ end
+
+ it 'does not yield diffs before the offset' do
+ expect(subject.to_a.map(&:diff)).to eq(
+ [
+ diff(fake_diff(3, 3)),
+ diff(fake_diff(4, 4))
+ ]
+ )
+ end
+
+ context 'when go over safe limits on bytes' do
+ let(:iterator) do
+ [
+ fake_diff(1, 10), # 10
+ fake_diff(1, 10), # 20
+ fake_diff(1, 15), # 35
+ fake_diff(1, 20), # 55
+ fake_diff(1, 45), # 100 - limit hit
+ fake_diff(1, 45),
+ fake_diff(1, 20480),
+ fake_diff(1, 1)
+ ]
+ end
+
+ before do
+ stub_const('Gitlab::Git::DiffCollection::DEFAULT_LIMITS',
+ { max_files: max_files, max_lines: 80 })
+ end
+
+ it 'considers size of diffs before the offset for prunning' do
+ expect(subject.to_a.map(&:diff)).to eq(
+ [
+ diff(fake_diff(1, 15)),
+ diff(fake_diff(1, 20))
+ ]
+ )
+ end
+ end
+ end
end
def fake_diff(line_length, line_count)