Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/diff/file_spec.rb')
-rw-r--r--spec/lib/gitlab/diff/file_spec.rb76
1 files changed, 66 insertions, 10 deletions
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb
index 9e5d3ab0a20..1fbb6465429 100644
--- a/spec/lib/gitlab/diff/file_spec.rb
+++ b/spec/lib/gitlab/diff/file_spec.rb
@@ -8,7 +8,9 @@ RSpec.describe Gitlab::Diff::File do
let_it_be(:project) { create(:project, :repository) }
let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.raw_diffs.first }
- let(:diff_file) { described_class.new(diff, diff_refs: commit.diff_refs, repository: project.repository) }
+ let(:diff_file) do
+ described_class.new(diff, diff_refs: commit.diff_refs, repository: project.repository)
+ end
def create_file(file_name, content)
Files::CreateService.new(
@@ -285,18 +287,72 @@ RSpec.describe Gitlab::Diff::File do
end
describe '#old_blob and #new_blob' do
- it 'returns blob of base commit and the new commit' do
- items = [
- [diff_file.new_content_sha, diff_file.new_path], [diff_file.old_content_sha, diff_file.old_path]
- ]
+ context 'when increase_diff_file_performance is on' do
+ let(:diff_file) do
+ described_class.new(diff, diff_refs: commit.diff_refs, repository: project.repository, max_blob_size: max_blob_size)
+ end
+
+ let(:max_blob_size) { 1000 }
+
+ before do
+ stub_feature_flags(increase_diff_file_performance: true)
+ end
+
+ context 'when the blobs are truncated' do
+ let(:max_blob_size) { 10 }
+
+ it 'returns the truncated blobs' do
+ items = [
+ [diff_file.new_content_sha, diff_file.new_path], [diff_file.old_content_sha, diff_file.old_path]
+ ]
+
+ expect(project.repository).to receive(:blobs_at).with(items, blob_size_limit: max_blob_size).and_call_original
+
+ old_data = diff_file.old_blob.data
+ data = diff_file.new_blob.data
+
+ expect(old_data.size).to eq(max_blob_size)
+ expect(data.size).to eq(max_blob_size)
+ end
+ end
- expect(project.repository).to receive(:blobs_at).with(items, blob_size_limit: 10.megabytes).and_call_original
+ it 'returns blob of base commit and the new commit' do
+ items = [
+ [diff_file.new_content_sha, diff_file.new_path], [diff_file.old_content_sha, diff_file.old_path]
+ ]
- old_data = diff_file.old_blob.data
- data = diff_file.new_blob.data
+ expect(project.repository).to receive(:blobs_at).with(items, blob_size_limit: max_blob_size).and_call_original
- expect(old_data).to include('raise "System commands must be given as an array of strings"')
- expect(data).to include('raise RuntimeError, "System commands must be given as an array of strings"')
+ old_data = diff_file.old_blob.data
+ data = diff_file.new_blob.data
+
+ expect(old_data).to include('raise "System commands must be given as an array of strings"')
+ expect(data).to include('raise RuntimeError, "System commands must be given as an array of strings"')
+ end
+ end
+
+ context 'when increase_diff_file_performance is off' do
+ let(:diff_file) do
+ described_class.new(diff, diff_refs: commit.diff_refs, repository: project.repository)
+ end
+
+ before do
+ stub_feature_flags(increase_diff_file_performance: false)
+ end
+
+ it 'returns blob of base commit and the new commit' do
+ items = [
+ [diff_file.new_content_sha, diff_file.new_path], [diff_file.old_content_sha, diff_file.old_path]
+ ]
+
+ expect(project.repository).to receive(:blobs_at).with(items, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE).and_call_original
+
+ old_data = diff_file.old_blob.data
+ data = diff_file.new_blob.data
+
+ expect(old_data).to include('raise "System commands must be given as an array of strings"')
+ expect(data).to include('raise RuntimeError, "System commands must be given as an array of strings"')
+ end
end
end