debian-mirror-gitlab/spec/lib/gitlab/checks/single_change_access_spec.rb

110 lines
3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2021-09-04 01:27:46 +05:30
RSpec.describe Gitlab::Checks::SingleChangeAccess do
2020-10-24 23:57:45 +05:30
describe '#validate!' do
2019-02-15 15:39:39 +05:30
include_context 'change access checks context'
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
subject { change_access }
2016-09-13 17:45:13 +05:30
context 'without failed checks' do
2017-09-10 17:25:29 +05:30
it "doesn't raise an error" do
2020-10-24 23:57:45 +05:30
expect { subject.validate! }.not_to raise_error
2016-09-13 17:45:13 +05:30
end
2019-02-15 15:39:39 +05:30
it 'calls pushes checks' do
2020-01-01 13:55:28 +05:30
expect_next_instance_of(Gitlab::Checks::PushCheck) do |instance|
expect(instance).to receive(:validate!)
end
2018-12-13 13:39:08 +05:30
2020-10-24 23:57:45 +05:30
subject.validate!
2018-12-13 13:39:08 +05:30
end
2019-02-15 15:39:39 +05:30
it 'calls branches checks' do
2020-01-01 13:55:28 +05:30
expect_next_instance_of(Gitlab::Checks::BranchCheck) do |instance|
expect(instance).to receive(:validate!)
end
2016-09-13 17:45:13 +05:30
2020-10-24 23:57:45 +05:30
subject.validate!
2016-09-13 17:45:13 +05:30
end
2019-02-15 15:39:39 +05:30
it 'calls tags checks' do
2020-01-01 13:55:28 +05:30
expect_next_instance_of(Gitlab::Checks::TagCheck) do |instance|
expect(instance).to receive(:validate!)
end
2016-09-13 17:45:13 +05:30
2020-10-24 23:57:45 +05:30
subject.validate!
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
it 'calls diff checks' do
2020-01-01 13:55:28 +05:30
expect_next_instance_of(Gitlab::Checks::DiffCheck) do |instance|
expect(instance).to receive(:validate!)
end
2017-09-10 17:25:29 +05:30
2020-10-24 23:57:45 +05:30
subject.validate!
2016-09-13 17:45:13 +05:30
end
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
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)
2019-01-03 12:48:30 +05:30
2020-10-24 23:57:45 +05:30
expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError)
2018-03-17 18:26:18 +05:30
end
end
2021-10-27 15:23:28 +05:30
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
2016-09-13 17:45:13 +05:30
end
end