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: 4e3681cd943364361d39614ddc084e1550655e3e (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
# frozen_string_literal: true

require 'spec_helper'

describe "CI YML Templates" do
  ABSTRACT_TEMPLATES = %w[Serverless].freeze
  # These templates depend on the presence of the `project`
  # param to enable processing of `include:` within CI config.
  PROJECT_DEPENDENT_TEMPLATES = %w[Auto-DevOps DAST].freeze

  def self.concrete_templates
    Gitlab::Template::GitlabCiYmlTemplate.all.reject do |template|
      ABSTRACT_TEMPLATES.include?(template.name)
    end
  end

  def self.abstract_templates
    Gitlab::Template::GitlabCiYmlTemplate.all.select do |template|
      ABSTRACT_TEMPLATES.include?(template.name)
    end
  end

  describe 'concrete templates with CI/CD jobs' do
    concrete_templates.each do |template|
      it "#{template.name} template should be valid" do
        # Trigger processing of included files
        project = create(:project, :test_repo) if PROJECT_DEPENDENT_TEMPLATES.include?(template.name)

        expect { Gitlab::Ci::YamlProcessor.new(template.content, project: project) }
          .not_to raise_error
      end
    end
  end

  describe 'abstract templates without concrete jobs defined' do
    abstract_templates.each do |template|
      it "#{template.name} template should be valid after being implemented" do
        content = template.content + <<~EOS
          concrete_build_implemented_by_a_user:
            stage: build
            script: do something
        EOS

        expect { Gitlab::Ci::YamlProcessor.new(content) }.not_to raise_error
      end
    end
  end
end