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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/checks
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/checks')
-rw-r--r--spec/lib/gitlab/checks/changes_access_spec.rb201
-rw-r--r--spec/lib/gitlab/checks/matching_merge_request_spec.rb3
-rw-r--r--spec/lib/gitlab/checks/single_change_access_spec.rb47
3 files changed, 228 insertions, 23 deletions
diff --git a/spec/lib/gitlab/checks/changes_access_spec.rb b/spec/lib/gitlab/checks/changes_access_spec.rb
index a46732f8255..4a74dfcec34 100644
--- a/spec/lib/gitlab/checks/changes_access_spec.rb
+++ b/spec/lib/gitlab/checks/changes_access_spec.rb
@@ -3,40 +3,199 @@
require 'spec_helper'
RSpec.describe Gitlab::Checks::ChangesAccess do
+ include_context 'changes access checks context'
+
+ subject { changes_access }
+
describe '#validate!' do
- include_context 'changes access checks context'
+ shared_examples '#validate!' do
+ before do
+ allow(project).to receive(:lfs_enabled?).and_return(true)
+ end
- before do
- allow(project).to receive(:lfs_enabled?).and_return(true)
- end
+ context 'without failed checks' do
+ it "doesn't raise an error" do
+ expect { subject.validate! }.not_to raise_error
+ end
- subject { changes_access }
+ it 'calls lfs checks' do
+ expect_next_instance_of(Gitlab::Checks::LfsCheck) do |instance|
+ expect(instance).to receive(:validate!)
+ end
- context 'without failed checks' do
- it "doesn't raise an error" do
- expect { subject.validate! }.not_to raise_error
+ subject.validate!
+ end
end
- it 'calls lfs checks' do
- expect_next_instance_of(Gitlab::Checks::LfsCheck) do |instance|
- expect(instance).to receive(:validate!)
+ context 'when time limit was reached' do
+ it 'raises a TimeoutError' do
+ logger = Gitlab::Checks::TimedLogger.new(start_time: timeout.ago, timeout: timeout)
+ access = described_class.new(changes,
+ project: project,
+ user_access: user_access,
+ protocol: protocol,
+ logger: logger)
+
+ expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError)
end
+ end
+ end
+
+ context 'with batched commits enabled' do
+ before do
+ stub_feature_flags(changes_batch_commits: true)
+ end
+
+ it_behaves_like '#validate!'
+ end
+
+ context 'with batched commits disabled' do
+ before do
+ stub_feature_flags(changes_batch_commits: false)
+ end
+
+ it_behaves_like '#validate!'
+ end
+ end
+
+ describe '#commits' do
+ it 'calls #new_commits' do
+ expect(project.repository).to receive(:new_commits).and_call_original
+
+ expect(subject.commits).to eq([])
+ end
+
+ context 'when changes contain empty revisions' do
+ let(:changes) { [{ newrev: newrev }, { newrev: '' }, { newrev: Gitlab::Git::BLANK_SHA }] }
+ let(:expected_commit) { instance_double(Commit) }
+
+ it 'returns only commits with non empty revisions' do
+ expect(project.repository).to receive(:new_commits).with([newrev], { allow_quarantine: true }) { [expected_commit] }
+ expect(subject.commits).to eq([expected_commit])
+ end
+ end
+ end
+
+ describe '#commits_for' do
+ let(:new_commits) { [] }
+ let(:expected_commits) { [] }
+
+ shared_examples 'a listing of new commits' do
+ it 'returns expected commits' do
+ expect(subject).to receive(:commits).and_return(new_commits)
+
+ expect(subject.commits_for(newrev)).to eq(expected_commits)
+ end
+ end
+
+ context 'with no commits' do
+ it_behaves_like 'a listing of new commits'
+ end
+
+ context 'with unrelated commits' do
+ let(:new_commits) { [create_commit('1234', %w[1111 2222])] }
+
+ it_behaves_like 'a listing of new commits'
+ end
+
+ context 'with single related commit' do
+ let(:new_commits) { [create_commit(newrev, %w[1111 2222])] }
+ let(:expected_commits) { new_commits }
- subject.validate!
+ it_behaves_like 'a listing of new commits'
+ end
+
+ context 'with single related and unrelated commit' do
+ let(:new_commits) do
+ [
+ create_commit(newrev, %w[1111 2222]),
+ create_commit('abcd', %w[1111 2222])
+ ]
+ end
+
+ let(:expected_commits) do
+ [create_commit(newrev, %w[1111 2222])]
end
+
+ it_behaves_like 'a listing of new commits'
end
- context 'when time limit was reached' do
- it 'raises a TimeoutError' do
- logger = Gitlab::Checks::TimedLogger.new(start_time: timeout.ago, timeout: timeout)
- access = described_class.new(changes,
- project: project,
- user_access: user_access,
- protocol: protocol,
- logger: logger)
+ context 'with multiple related commits' do
+ let(:new_commits) do
+ [
+ create_commit(newrev, %w[1111]),
+ create_commit('1111', %w[2222]),
+ create_commit('abcd', [])
+ ]
+ end
- expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError)
+ let(:expected_commits) do
+ [
+ create_commit(newrev, %w[1111]),
+ create_commit('1111', %w[2222])
+ ]
end
+
+ it_behaves_like 'a listing of new commits'
end
+
+ context 'with merge commits' do
+ let(:new_commits) do
+ [
+ create_commit(newrev, %w[1111 2222 3333]),
+ create_commit('1111', []),
+ create_commit('3333', %w[4444]),
+ create_commit('4444', [])
+ ]
+ end
+
+ let(:expected_commits) do
+ [
+ create_commit(newrev, %w[1111 2222 3333]),
+ create_commit('1111', []),
+ create_commit('3333', %w[4444]),
+ create_commit('4444', [])
+ ]
+ end
+
+ it_behaves_like 'a listing of new commits'
+ end
+
+ context 'with criss-cross merges' do
+ let(:new_commits) do
+ [
+ create_commit(newrev, %w[a1 b1]),
+ create_commit('a1', %w[a2 b2]),
+ create_commit('a2', %w[a3 b3]),
+ create_commit('a3', %w[c]),
+ create_commit('b1', %w[b2 a2]),
+ create_commit('b2', %w[b3 a3]),
+ create_commit('b3', %w[c]),
+ create_commit('c', [])
+ ]
+ end
+
+ let(:expected_commits) do
+ [
+ create_commit(newrev, %w[a1 b1]),
+ create_commit('a1', %w[a2 b2]),
+ create_commit('b1', %w[b2 a2]),
+ create_commit('a2', %w[a3 b3]),
+ create_commit('b2', %w[b3 a3]),
+ create_commit('a3', %w[c]),
+ create_commit('b3', %w[c]),
+ create_commit('c', [])
+ ]
+ end
+
+ it_behaves_like 'a listing of new commits'
+ end
+ end
+
+ def create_commit(id, parent_ids)
+ Gitlab::Git::Commit.new(project.repository, {
+ id: id,
+ parent_ids: parent_ids
+ })
end
end
diff --git a/spec/lib/gitlab/checks/matching_merge_request_spec.rb b/spec/lib/gitlab/checks/matching_merge_request_spec.rb
index feda488a936..2e562a5a350 100644
--- a/spec/lib/gitlab/checks/matching_merge_request_spec.rb
+++ b/spec/lib/gitlab/checks/matching_merge_request_spec.rb
@@ -49,12 +49,11 @@ RSpec.describe Gitlab::Checks::MatchingMergeRequest do
end
end
- context 'with load balancing enabled', :request_store, :redis do
+ context 'with load balancing enabled', :db_load_balancing do
let(:session) { ::Gitlab::Database::LoadBalancing::Session.current }
let(:all_caught_up) { true }
before do
- expect(::Gitlab::Database::LoadBalancing).to receive(:enable?).at_least(:once).and_return(true)
allow(::Gitlab::Database::LoadBalancing::Sticking).to receive(:all_caught_up?).and_return(all_caught_up)
expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:select_valid_host).with(:project, project.id).and_call_original
diff --git a/spec/lib/gitlab/checks/single_change_access_spec.rb b/spec/lib/gitlab/checks/single_change_access_spec.rb
index 8b235005b3e..e81e4951539 100644
--- a/spec/lib/gitlab/checks/single_change_access_spec.rb
+++ b/spec/lib/gitlab/checks/single_change_access_spec.rb
@@ -58,5 +58,52 @@ RSpec.describe Gitlab::Checks::SingleChangeAccess do
expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError)
end
end
+
+ describe '#commits' do
+ let(:expected_commits) { [Gitlab::Git::Commit.new(project.repository, { id: "1234" })] }
+
+ let(:access) do
+ described_class.new(changes,
+ project: project,
+ user_access: user_access,
+ protocol: protocol,
+ logger: logger,
+ commits: provided_commits)
+ end
+
+ shared_examples '#commits' do
+ it 'returns expected commits' do
+ expect(access.commits).to eq(expected_commits)
+ end
+
+ it 'returns expected commits on repeated calls' do
+ expect(access.commits).to eq(expected_commits)
+ expect(access.commits).to eq(expected_commits)
+ end
+ end
+
+ context 'with provided commits' do
+ let(:provided_commits) { expected_commits }
+
+ before do
+ expect(project.repository).not_to receive(:new_commits)
+ end
+
+ it_behaves_like '#commits'
+ end
+
+ context 'without provided commits' do
+ let(:provided_commits) { nil }
+
+ before do
+ expect(project.repository)
+ .to receive(:new_commits)
+ .once
+ .and_return(expected_commits)
+ end
+
+ it_behaves_like '#commits'
+ end
+ end
end
end