2018-09-26 11:39:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe 'CI YML Templates' do
|
2020-09-01 14:10:48 -04:00
|
|
|
subject { Gitlab::Ci::YamlProcessor.new(content).execute }
|
2019-04-05 06:18:10 -04:00
|
|
|
|
2020-02-18 10:08:51 -05:00
|
|
|
let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) }
|
2020-09-08 08:08:41 -04:00
|
|
|
let(:excluded_templates) do
|
2022-05-12 23:08:13 -04:00
|
|
|
all_templates.select do |name|
|
2020-09-08 08:08:41 -04:00
|
|
|
Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) }
|
2019-04-05 06:18:10 -04:00
|
|
|
end
|
2020-02-18 10:08:51 -05:00
|
|
|
end
|
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
shared_examples 'require default stages to be included' do
|
|
|
|
it 'require default stages to be included' do
|
|
|
|
expect(subject.stages).to include(*Gitlab::Ci::Config::Entry::Stages.default)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'that support autodevops' do
|
2021-06-16 14:10:35 -04:00
|
|
|
exceptions = [
|
|
|
|
'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml
|
|
|
|
'Security/DAST-API.gitlab-ci.yml', # no auto-devops
|
2022-04-18 17:08:27 -04:00
|
|
|
'Security/API-Fuzzing.gitlab-ci.yml', # no auto-devops
|
|
|
|
'ThemeKit.gitlab-ci.yml'
|
2021-06-14 20:10:11 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
context 'when including available templates in a CI YAML configuration' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:template_name) do
|
2021-06-16 14:10:35 -04:00
|
|
|
all_templates - excluded_templates - exceptions
|
2021-06-14 20:10:11 -04:00
|
|
|
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_expected.to be_valid }
|
2019-04-05 06:18:10 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
include_examples 'require default stages to be included'
|
|
|
|
end
|
2019-02-27 12:12:28 -05:00
|
|
|
end
|
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
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_expected.not_to be_valid }
|
|
|
|
end
|
2021-06-04 14:10:08 -04:00
|
|
|
end
|
2021-06-14 20:10:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'that do not support autodevops' do
|
|
|
|
context 'when DAST API template' do
|
|
|
|
# The DAST API template purposly excludes a stages
|
|
|
|
# definition.
|
|
|
|
|
|
|
|
let(:template_name) { 'Security/DAST-API.gitlab-ci.yml' }
|
2021-06-04 14:10:08 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
context 'with default stages' do
|
|
|
|
let(:content) do
|
|
|
|
<<~EOS
|
|
|
|
include:
|
|
|
|
- template: #{template_name}
|
|
|
|
|
|
|
|
concrete_build_implemented_by_a_user:
|
|
|
|
stage: test
|
|
|
|
script: do something
|
|
|
|
EOS
|
|
|
|
end
|
2020-02-18 10:08:51 -05:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
it { is_expected.not_to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with defined stages' do
|
|
|
|
let(:content) do
|
2021-05-11 17:10:21 -04:00
|
|
|
<<~EOS
|
|
|
|
include:
|
|
|
|
- template: #{template_name}
|
|
|
|
|
|
|
|
stages:
|
|
|
|
- build
|
|
|
|
- test
|
|
|
|
- deploy
|
|
|
|
- dast
|
|
|
|
|
|
|
|
concrete_build_implemented_by_a_user:
|
|
|
|
stage: test
|
|
|
|
script: do something
|
|
|
|
EOS
|
2021-06-14 20:10:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
|
|
|
|
include_examples 'require default stages to be included'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when API Fuzzing template' do
|
|
|
|
# The API Fuzzing template purposly excludes a stages
|
|
|
|
# definition.
|
|
|
|
|
|
|
|
let(:template_name) { 'Security/API-Fuzzing.gitlab-ci.yml' }
|
|
|
|
|
|
|
|
context 'with default stages' do
|
|
|
|
let(:content) do
|
2021-05-11 17:10:21 -04:00
|
|
|
<<~EOS
|
|
|
|
include:
|
|
|
|
- template: #{template_name}
|
|
|
|
|
|
|
|
concrete_build_implemented_by_a_user:
|
|
|
|
stage: test
|
|
|
|
script: do something
|
|
|
|
EOS
|
|
|
|
end
|
2020-02-18 10:08:51 -05:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
it { is_expected.not_to be_valid }
|
2020-02-18 10:08:51 -05:00
|
|
|
end
|
2020-09-08 08:08:41 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
context 'with defined stages' do
|
|
|
|
let(:content) do
|
|
|
|
<<~EOS
|
|
|
|
include:
|
|
|
|
- template: #{template_name}
|
2020-09-08 08:08:41 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
stages:
|
|
|
|
- build
|
|
|
|
- test
|
|
|
|
- deploy
|
|
|
|
- fuzz
|
2020-09-08 08:08:41 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
concrete_build_implemented_by_a_user:
|
|
|
|
stage: test
|
|
|
|
script: do something
|
|
|
|
EOS
|
|
|
|
end
|
2020-09-08 08:08:41 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
it { is_expected.to be_valid }
|
2020-09-08 08:08:41 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
include_examples 'require default stages to be included'
|
2020-09-08 08:08:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-09-26 11:39:27 -04:00
|
|
|
end
|