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

70 lines
1.6 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) }
2019-07-07 11:18:12 +05:30
2020-11-24 15:15:51 +05:30
let(:excluded_templates) do
all_templates.select do |name|
Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) }
2019-07-31 22:56:46 +05:30
end
2020-04-08 14:13:33 +05:30
end
2020-11-24 15:15:51 +05:30
context 'when including available templates in a CI YAML configuration' do
2020-04-08 14:13:33 +05:30
using RSpec::Parameterized::TableSyntax
2019-07-31 22:56:46 +05:30
2020-04-08 14:13:33 +05:30
where(:template_name) do
2020-11-24 15:15:51 +05:30
all_templates - excluded_templates
2019-07-07 11:18:12 +05:30
end
2020-04-08 14:13:33 +05:30
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 valid' do
2020-11-24 15:15:51 +05:30
expect(subject).to be_valid
2020-04-08 14:13:33 +05:30
end
it 'require default stages to be included' do
expect(subject.stages).to include(*Gitlab::Ci::Config::Entry::Stages.default)
end
2018-12-05 23:21:45 +05:30
end
end
2020-11-24 15:15:51 +05:30
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
2018-12-05 23:21:45 +05:30
end