change_access_spec.rb 1.61 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
describe Gitlab::Checks::ChangeAccess do
6
  describe '#exec' do
7
    include_context 'change access checks context'
8

9
    subject { change_access }
10 11

    context 'without failed checks' do
12
      it "doesn't raise an error" do
13
        expect { subject.exec }.not_to raise_error
14 15
      end

16 17
      it 'calls pushes checks' do
        expect_any_instance_of(Gitlab::Checks::PushCheck).to receive(:validate!)
18

19
        subject.exec
20 21
      end

22 23
      it 'calls branches checks' do
        expect_any_instance_of(Gitlab::Checks::BranchCheck).to receive(:validate!)
24

25
        subject.exec
26 27
      end

28 29
      it 'calls tags checks' do
        expect_any_instance_of(Gitlab::Checks::TagCheck).to receive(:validate!)
30

31
        subject.exec
32
      end
33

34 35
      it 'calls lfs checks' do
        expect_any_instance_of(Gitlab::Checks::LfsCheck).to receive(:validate!)
36

37
        subject.exec
38
      end
39

40 41
      it 'calls diff checks' do
        expect_any_instance_of(Gitlab::Checks::DiffCheck).to receive(:validate!)
42

43
        subject.exec
44 45
      end
    end
46

47 48 49 50 51 52 53 54
    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)
55

56
        expect { access.exec }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError)
57 58
      end
    end
59 60
  end
end