2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
|
2020-06-23 00:09:42 +05:30
|
|
|
before do
|
|
|
|
stub_const('MutatingConstantIterator', Class.new)
|
|
|
|
|
|
|
|
MutatingConstantIterator.class_eval do
|
|
|
|
include Enumerable
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
attr_reader :size
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def initialize(count, value)
|
|
|
|
@count = count
|
2021-01-03 14:25:43 +05:30
|
|
|
@size = count
|
2020-06-23 00:09:42 +05:30
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
return enum_for(:each) unless block_given?
|
|
|
|
|
|
|
|
loop do
|
2020-10-24 23:57:45 +05:30
|
|
|
break if @count == 0
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
# It is critical to decrement before yielding. We may never reach the lines after 'yield'.
|
|
|
|
@count -= 1
|
|
|
|
yield @value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
subject do
|
|
|
|
Gitlab::Git::DiffCollection.new(
|
|
|
|
iterator,
|
|
|
|
max_files: max_files,
|
|
|
|
max_lines: max_lines,
|
2017-09-10 17:25:29 +05:30
|
|
|
limits: limits,
|
|
|
|
expanded: expanded
|
2017-08-17 22:00:37 +05:30
|
|
|
)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:iterator) { MutatingConstantIterator.new(file_count, fake_diff(line_length, line_count)) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:file_count) { 0 }
|
|
|
|
let(:line_length) { 1 }
|
|
|
|
let(:line_count) { 1 }
|
|
|
|
let(:max_files) { 10 }
|
|
|
|
let(:max_lines) { 100 }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { true }
|
|
|
|
let(:expanded) { true }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#to_a' do
|
|
|
|
subject { super().to_a }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_kind_of ::Array }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#decorate!' do
|
|
|
|
let(:file_count) { 3 }
|
|
|
|
|
|
|
|
it 'modifies the array in place' do
|
|
|
|
count = 0
|
|
|
|
subject.decorate! { |d| !d.nil? && count += 1 }
|
|
|
|
expect(subject.to_a).to eq([1, 2, 3])
|
|
|
|
expect(count).to eq(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'avoids future iterator iterations' do
|
|
|
|
subject.decorate! { |d| d unless d.nil? }
|
|
|
|
|
|
|
|
expect(iterator).not_to receive(:each)
|
|
|
|
|
|
|
|
subject.overflow?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'overflow handling' do
|
|
|
|
context 'adding few enough files' do
|
|
|
|
let(:file_count) { 3 }
|
|
|
|
|
|
|
|
context 'and few enough lines' do
|
|
|
|
let(:line_count) { 10 }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('3') }
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe '#size' do
|
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
|
|
|
|
it 'does not change after peeking' do
|
|
|
|
subject.any?
|
|
|
|
expect(subject.size).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when limiting is disabled' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('3') }
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe '#size' do
|
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
|
|
|
|
it 'does not change after peeking' do
|
|
|
|
subject.any?
|
|
|
|
expect(subject.size).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and too many lines' do
|
|
|
|
let(:line_count) { 1000 }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('0+') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq 1000 }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(0) }
|
|
|
|
|
|
|
|
context 'when limiting is disabled' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('3') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'adding too many files' do
|
|
|
|
let(:file_count) { 11 }
|
|
|
|
|
|
|
|
context 'and few enough lines' do
|
|
|
|
let(:line_count) { 1 }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('10+') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq 10 }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(10) }
|
|
|
|
|
|
|
|
context 'when limiting is disabled' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('11') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(11) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and too many lines' do
|
|
|
|
let(:line_count) { 30 }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('3+') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq 120 }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
|
|
|
|
context 'when limiting is disabled' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('11') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(11) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'adding exactly the maximum number of files' do
|
|
|
|
let(:file_count) { 10 }
|
|
|
|
|
|
|
|
context 'and few enough lines' do
|
|
|
|
let(:line_count) { 1 }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('10') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(10) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'adding too many bytes' do
|
|
|
|
let(:file_count) { 10 }
|
|
|
|
let(:line_length) { 5200 }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('9+') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(9) }
|
|
|
|
|
|
|
|
context 'when limiting is disabled' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('10') }
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq file_count * line_count }
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.size).to eq(10) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'empty collection' do
|
|
|
|
subject { Gitlab::Git::DiffCollection.new([]) }
|
|
|
|
|
|
|
|
describe '#overflow?' do
|
|
|
|
subject { super().overflow? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#size' do
|
|
|
|
subject { super().size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#real_size' do
|
|
|
|
subject { super().real_size }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to eq('0')}
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#line_count' do
|
|
|
|
subject { super().line_count }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it { is_expected.to eq 0 }
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#each' do
|
|
|
|
context 'when diff are too large' do
|
|
|
|
let(:collection) do
|
|
|
|
Gitlab::Git::DiffCollection.new([{ diff: 'a' * 204800 }])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'yields Diff instances even when they are too large' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { |b| collection.each(&b) }
|
|
|
|
.to yield_with_args(an_instance_of(Gitlab::Git::Diff))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'prunes diffs that are too large' do
|
|
|
|
diff = nil
|
|
|
|
|
|
|
|
collection.each do |d|
|
|
|
|
diff = d
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(diff.diff).to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diff is quite large will collapse by default' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:iterator) { [{ diff: 'a' * 20480 }] }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'when no collapse is set' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:expanded) { true }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'yields Diff instances even when they are quite big' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { |b| subject.each(&b) }
|
|
|
|
.to yield_with_args(an_instance_of(Gitlab::Git::Diff))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not prune diffs' do
|
|
|
|
diff = nil
|
|
|
|
|
|
|
|
subject.each do |d|
|
|
|
|
diff = d
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(diff.diff).not_to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no collapse is unset' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:expanded) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'yields Diff instances even when they are quite big' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { |b| subject.each(&b) }
|
|
|
|
.to yield_with_args(an_instance_of(Gitlab::Git::Diff))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'single-file collections' do
|
|
|
|
it 'does not prune diffs' do
|
|
|
|
diff = nil
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
subject.each do |d|
|
|
|
|
diff = d
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(diff.diff).not_to eq('')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'multi-file collections' do
|
|
|
|
let(:iterator) { [{ diff: 'b' }, { diff: 'a' * 20480 }]}
|
|
|
|
|
|
|
|
it 'prunes diffs that are quite big' do
|
|
|
|
diff = nil
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
subject.each do |d|
|
|
|
|
diff = d
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(diff.diff).to eq('')
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when go over safe limits on files' do
|
|
|
|
let(:iterator) { [fake_diff(1, 1)] * 4 }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
2021-01-03 14:25:43 +05:30
|
|
|
allow(Gitlab::Git::DiffCollection)
|
|
|
|
.to receive(:default_limits)
|
|
|
|
.and_return({ max_files: 2, max_lines: max_lines })
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'prunes diffs by default even little ones' do
|
|
|
|
subject.each_with_index do |d, i|
|
|
|
|
if i < 2
|
|
|
|
expect(d.diff).not_to eq('')
|
|
|
|
else # 90 lines
|
|
|
|
expect(d.diff).to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when go over safe limits on lines' do
|
|
|
|
let(:iterator) do
|
|
|
|
[
|
|
|
|
fake_diff(1, 45),
|
|
|
|
fake_diff(1, 45),
|
|
|
|
fake_diff(1, 20480),
|
|
|
|
fake_diff(1, 1)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
2021-01-03 14:25:43 +05:30
|
|
|
allow(Gitlab::Git::DiffCollection)
|
|
|
|
.to receive(:default_limits)
|
|
|
|
.and_return({ max_files: max_files, max_lines: 80 })
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'prunes diffs by default even little ones' do
|
|
|
|
subject.each_with_index do |d, i|
|
|
|
|
if i < 2
|
|
|
|
expect(d.diff).not_to eq('')
|
|
|
|
else # 90 lines
|
|
|
|
expect(d.diff).to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when go over safe limits on bytes' do
|
|
|
|
let(:iterator) do
|
|
|
|
[
|
|
|
|
fake_diff(1, 45),
|
|
|
|
fake_diff(1, 45),
|
|
|
|
fake_diff(1, 20480),
|
|
|
|
fake_diff(1, 1)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
2021-01-03 14:25:43 +05:30
|
|
|
allow(Gitlab::Git::DiffCollection)
|
|
|
|
.to receive(:default_limits)
|
|
|
|
.and_return({ max_files: max_files, max_lines: 80 })
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'prunes diffs by default even little ones' do
|
|
|
|
subject.each_with_index do |d, i|
|
|
|
|
if i < 2
|
|
|
|
expect(d.diff).not_to eq('')
|
|
|
|
else # > 80 bytes
|
|
|
|
expect(d.diff).to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when limiting is disabled' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:limits) { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'yields Diff instances even when they are quite big' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { |b| subject.each(&b) }
|
|
|
|
.to yield_with_args(an_instance_of(Gitlab::Git::Diff))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not prune diffs' do
|
|
|
|
diff = nil
|
|
|
|
|
|
|
|
subject.each do |d|
|
|
|
|
diff = d
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(diff.diff).not_to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
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
|
2021-01-03 14:25:43 +05:30
|
|
|
allow(Gitlab::Git::DiffCollection)
|
|
|
|
.to receive(:default_limits)
|
|
|
|
.and_return({ max_files: max_files, max_lines: 80 })
|
2019-12-21 20:55:43 +05:30
|
|
|
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
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def fake_diff(line_length, line_count)
|
|
|
|
{ 'diff' => "#{'a' * line_length}\n" * line_count }
|
|
|
|
end
|
|
|
|
end
|