debian-mirror-gitlab/spec/lib/gitlab/checks/single_change_access_spec.rb
2022-07-17 14:43:12 +02:00

122 lines
3.5 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Checks::SingleChangeAccess do
describe '#validate!' do
include_context 'change access checks context'
subject { change_access }
context 'without failed checks' do
it "doesn't raise an error" do
expect { subject.validate! }.not_to raise_error
end
it 'calls pushes checks' do
expect_next_instance_of(Gitlab::Checks::PushCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.validate!
end
it 'calls branches checks' do
expect_next_instance_of(Gitlab::Checks::BranchCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.validate!
end
it 'calls tags checks' do
expect_next_instance_of(Gitlab::Checks::TagCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.validate!
end
it 'calls diff checks' do
expect_next_instance_of(Gitlab::Checks::DiffCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.validate!
end
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)
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
stub_feature_flags(filter_quarantined_commits: filter_quarantined_commits)
expect(project.repository)
.to receive(:new_commits)
.with(newrev, allow_quarantine: filter_quarantined_commits)
.once
.and_return(expected_commits)
end
context 'with :filter_quarantined_commits disabled' do
let(:filter_quarantined_commits) { false }
it_behaves_like '#commits'
end
context 'with :filter_quarantined_commits enabled' do
let(:filter_quarantined_commits) { true }
it_behaves_like '#commits'
end
end
end
end
end