debian-mirror-gitlab/spec/lib/gitlab/ci/templates/templates_spec.rb

170 lines
4.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe 'CI YML Templates' do
2020-11-24 15:15:51 +05:30
subject { Gitlab::Ci::YamlProcessor.new(content).execute }
2019-07-31 22:56:46 +05:30
2020-04-08 14:13:33 +05:30
let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) }
2020-11-24 15:15:51 +05:30
let(:excluded_templates) do
2021-09-04 01:27:46 +05:30
excluded = all_templates.select do |name|
2020-11-24 15:15:51 +05:30
Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) }
2019-07-31 22:56:46 +05:30
end
2021-09-04 01:27:46 +05:30
excluded + ["Terraform.gitlab-ci.yml"]
2020-04-08 14:13:33 +05:30
end
2021-09-04 01:27:46 +05:30
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)
2019-07-07 11:18:12 +05:30
end
2021-09-04 01:27:46 +05:30
end
context 'that support autodevops' do
exceptions = [
'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml
'Security/DAST-API.gitlab-ci.yml', # no auto-devops
'Security/API-Fuzzing.gitlab-ci.yml' # no auto-devops
]
context 'when including available templates in a CI YAML configuration' do
using RSpec::Parameterized::TableSyntax
where(:template_name) do
all_templates - excluded_templates - exceptions
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 }
include_examples 'require default stages to be included'
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_expected.not_to be_valid }
end
end
end
describe 'that do not support autodevops' do
context 'when DAST API template' do
# The DAST API template purposly excludes a stages
# definition.
2019-07-07 11:18:12 +05:30
2021-09-04 01:27:46 +05:30
let(:template_name) { 'Security/DAST-API.gitlab-ci.yml' }
2020-04-08 14:13:33 +05:30
2021-09-04 01:27:46 +05:30
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
it { is_expected.not_to be_valid }
end
context 'with defined stages' do
let(:content) do
2021-06-08 01:23:25 +05:30
<<~EOS
include:
- template: #{template_name}
stages:
- build
- test
- deploy
- dast
concrete_build_implemented_by_a_user:
stage: test
script: do something
EOS
2021-09-04 01:27:46 +05:30
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-06-08 01:23:25 +05:30
<<~EOS
include:
- template: #{template_name}
concrete_build_implemented_by_a_user:
stage: test
script: do something
EOS
end
2020-04-08 14:13:33 +05:30
2021-09-04 01:27:46 +05:30
it { is_expected.not_to be_valid }
2020-04-08 14:13:33 +05:30
end
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
context 'with defined stages' do
let(:content) do
<<~EOS
include:
- template: #{template_name}
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
stages:
- build
- test
- deploy
- fuzz
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
concrete_build_implemented_by_a_user:
stage: test
script: do something
EOS
end
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
it { is_expected.to be_valid }
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
include_examples 'require default stages to be included'
2020-11-24 15:15:51 +05:30
end
end
end
2018-12-05 23:21:45 +05:30
end