summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/repository_size_checker_spec.rb
blob: 9b2c02b119092936917095d177d7a0912711b461 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::RepositorySizeChecker do
  let(:current_size) { 0 }
  let(:limit) { 50 }
  let(:enabled) { true }

  subject do
    described_class.new(
      current_size_proc: -> { current_size },
      limit: limit,
      enabled: enabled
    )
  end

  describe '#enabled?' do
    context 'when enabled' do
      it 'returns true' do
        expect(subject.enabled?).to be_truthy
      end
    end

    context 'when limit is zero' do
      let(:limit) { 0 }

      it 'returns false' do
        expect(subject.enabled?).to be_falsey
      end
    end
  end

  describe '#changes_will_exceed_size_limit?' do
    let(:current_size) { 49 }

    it 'returns true when changes go over' do
      expect(subject.changes_will_exceed_size_limit?(2)).to be_truthy
    end

    it 'returns false when changes do not go over' do
      expect(subject.changes_will_exceed_size_limit?(1)).to be_falsey
    end
  end

  describe '#above_size_limit?' do
    context 'when size is above the limit' do
      let(:current_size) { 100 }

      it 'returns true' do
        expect(subject.above_size_limit?).to be_truthy
      end
    end

    it 'returns false when not over the limit' do
      expect(subject.above_size_limit?).to be_falsey
    end
  end

  describe '#exceeded_size' do
    context 'when current size is below or equal to the limit' do
      let(:current_size) { 50 }

      it 'returns zero' do
        expect(subject.exceeded_size).to eq(0)
      end
    end

    context 'when current size is over the limit' do
      let(:current_size) { 51 }

      it 'returns zero' do
        expect(subject.exceeded_size).to eq(1)
      end
    end

    context 'when change size will be over the limit' do
      let(:current_size) { 50 }

      it 'returns zero' do
        expect(subject.exceeded_size(1)).to eq(1)
      end
    end

    context 'when change size will not be over the limit' do
      let(:current_size) { 49 }

      it 'returns zero' do
        expect(subject.exceeded_size(1)).to eq(0)
      end
    end
  end
end