summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/checks/single_change_access_spec.rb
blob: 8b235005b3eeaaa515647248df00f1a7351a5c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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
  end
end