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

templates_spec.rb « templates « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56443e611e813f62ce121b58d3bea047665f138f (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'CI YML Templates' do
  subject { Gitlab::Ci::YamlProcessor.new(content).execute }

  let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) }

  let(:excluded_templates) do
    all_templates.select do |name|
      Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) }
    end
  end

  context 'when including available templates in a CI YAML configuration' do
    using RSpec::Parameterized::TableSyntax

    where(:template_name) do
      all_templates - excluded_templates
    end

    with_them do
      let(:content) do
        if template_name == 'Security/DAST-API.gitlab-ci.yml'
          # The DAST-API template purposly excludes a stages
          # definition.

          <<~EOS
            include:
              - template: #{template_name}

            stages:
              - build
              - test
              - deploy
              - dast

            concrete_build_implemented_by_a_user:
              stage: test
              script: do something
          EOS
        else
          <<~EOS
            include:
              - template: #{template_name}

            concrete_build_implemented_by_a_user:
              stage: test
              script: do something
          EOS
        end
      end

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

      it 'require default stages to be included' do
        expect(subject.stages).to include(*Gitlab::Ci::Config::Entry::Stages.default)
      end
    end
  end

  context 'when including unavailable templates in a CI YAML configuration' do
    using RSpec::Parameterized::TableSyntax

    where(:template_name) do
      excluded_templates
    end

    with_them do
      let(:content) do
        <<~EOS
          include:
            - template: #{template_name}

          concrete_build_implemented_by_a_user:
            stage: test
            script: do something
        EOS
      end

      it 'is not valid' do
        expect(subject).not_to be_valid
      end
    end
  end
end