Welcome to mirror list, hosted at ThFree Co, Russian Federation.

workflow_spec.rb « entry « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 97ac199f47de6865a0435af12c00d063c9d8860f (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Entry::Workflow do
  let(:factory) { Gitlab::Config::Entry::Factory.new(described_class).value(rules_hash) }
  let(:config)  { factory.create! }

  describe 'validations' do
    context 'when work config value is a string' do
      let(:rules_hash) { 'build' }

      describe '#valid?' do
        it 'is invalid' do
          expect(config).not_to be_valid
        end

        it 'attaches an error specifying that workflow should point to a hash' do
          expect(config.errors).to include('workflow config should be a hash')
        end
      end

      describe '#value' do
        it 'returns the invalid configuration' do
          expect(config.value).to eq(rules_hash)
        end
      end
    end

    context 'when work config value is a hash' do
      let(:rules_hash) { { rules: [{ if: '$VAR' }] } }

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

        it 'attaches no errors' do
          expect(config.errors).to be_empty
        end
      end

      describe '#value' do
        it 'returns the config' do
          expect(config.value).to eq(rules_hash)
        end
      end

      context 'with an invalid key' do
        let(:rules_hash) { { trash: [{ if: '$VAR' }] } }

        describe '#valid?' do
          it 'is invalid' do
            expect(config).not_to be_valid
          end

          it 'attaches an error specifying the unknown key' do
            expect(config.errors).to include('workflow config contains unknown keys: trash')
          end
        end

        describe '#value' do
          it 'returns the invalid configuration' do
            expect(config.value).to eq(rules_hash)
          end
        end
      end

      context 'with workflow name' do
        let(:factory) { Gitlab::Config::Entry::Factory.new(described_class).value(workflow_hash) }

        context 'with a blank name' do
          let(:workflow_hash) do
            { name: '' }
          end

          it 'is invalid' do
            expect(config).not_to be_valid
          end

          it 'returns error about invalid name' do
            expect(config.errors).to include('workflow name is too short (minimum is 1 character)')
          end
        end

        context 'with too long name' do
          let(:workflow_hash) do
            { name: 'a' * 256 }
          end

          it 'is invalid' do
            expect(config).not_to be_valid
          end

          it 'returns error about invalid name' do
            expect(config.errors).to include('workflow name is too long (maximum is 255 characters)')
          end
        end

        context 'when name is nil' do
          let(:workflow_hash) { { name: nil } }

          it 'is valid' do
            expect(config).to be_valid
          end
        end

        context 'when name is not provided' do
          let(:workflow_hash) { { rules: [{ if: '$VAR' }] } }

          it 'is valid' do
            expect(config).to be_valid
          end
        end
      end
    end
  end

  describe '.default' do
    it 'is nil' do
      expect(described_class.default).to be_nil
    end
  end
end