summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/entry/tags_spec.rb
blob: 79317de373b72dc2167f32a0f3c7da8210427fb3 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Entry::Tags do
  let(:entry) { described_class.new(config) }

  describe 'validation' do
    context 'when tags config value is correct' do
      let(:config) { %w[tag1 tag2] }

      describe '#value' do
        it 'returns tags configuration' do
          expect(entry.value).to eq config
        end
      end

      describe '#valid?' do
        it 'is valid' do
          expect(entry).to be_valid
        end
      end
    end

    context 'when entry value is not correct' do
      describe '#errors' do
        context 'when tags config is not an array of strings' do
          let(:config) { [1, 2] }

          it 'reports error' do
            expect(entry.errors)
              .to include 'tags config should be an array of strings'
          end
        end

        context 'when tags limit is reached' do
          let(:config) { Array.new(50) {|i| "tag-#{i}" } }

          context 'when ci_build_tags_limit is enabled' do
            before do
              stub_feature_flags(ci_build_tags_limit: true)
            end

            it 'reports error' do
              expect(entry.errors)
                .to include "tags config must be less than the limit of #{described_class::TAGS_LIMIT} tags"
            end
          end

          context 'when ci_build_tags_limit is disabled' do
            before do
              stub_feature_flags(ci_build_tags_limit: false)
            end

            it 'does not report an error' do
              expect(entry.errors).to be_empty
            end
          end
        end
      end
    end
  end
end