summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-04-15 12:25:32 +0000
committerSean McGivern <sean@gitlab.com>2019-04-15 12:25:32 +0000
commit0c0be8d68e8f899da4e80dd4bdf44a01dfa54cee (patch)
treeb4f5c98f218c76929f00f3c88bd63368d17a77dd /spec
parentffb6995f654eb2de63c7a295221f4fe4e2650877 (diff)
parentef84f7bbe249980c248c4000958cd145be1b28ba (diff)
downloadgitlab-ce-0c0be8d68e8f899da4e80dd4bdf44a01dfa54cee.tar.gz
Merge branch 'cherry-pick-39eb16aa' into 'master'
Pick revert of `require-all-templates-to-include-default-stages' Closes #59992 and #60106 See merge request gitlab-org/gitlab-ce!27312
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/templates/templates_spec.rb54
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb19
2 files changed, 33 insertions, 40 deletions
diff --git a/spec/lib/gitlab/ci/templates/templates_spec.rb b/spec/lib/gitlab/ci/templates/templates_spec.rb
index 4e3681cd943..b52064b3036 100644
--- a/spec/lib/gitlab/ci/templates/templates_spec.rb
+++ b/spec/lib/gitlab/ci/templates/templates_spec.rb
@@ -3,46 +3,32 @@
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
+ using RSpec::Parameterized::TableSyntax
- def self.abstract_templates
- Gitlab::Template::GitlabCiYmlTemplate.all.select do |template|
- ABSTRACT_TEMPLATES.include?(template.name)
- end
+ subject { Gitlab::Ci::YamlProcessor.new(content) }
+
+ where(:template_name) do
+ Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name)
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)
+ with_them do
+ let(:content) do
+ <<~EOS
+ include:
+ - template: #{template_name}
- expect { Gitlab::Ci::YamlProcessor.new(template.content, project: project) }
- .not_to raise_error
- end
+ concrete_build_implemented_by_a_user:
+ stage: test
+ script: do something
+ EOS
+ end
+
+ it 'is valid' do
+ expect { subject }.not_to raise_error
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
+ it 'require default stages to be included' do
+ expect(subject.stages).to include(*Gitlab::Ci::Config::Entry::Stages.default)
end
end
end
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index b7b30e60d44..0d998d89d73 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -615,19 +615,19 @@ module Gitlab
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config), opts) }
context "when validating a ci config file with no project context" do
- context "when a single string is provided", :quarantine do
+ context "when a single string is provided" do
let(:include_content) { "/local.gitlab-ci.yml" }
- it "does not return any error" do
- expect { subject }.not_to raise_error
+ it "returns a validation error" do
+ expect { subject }.to raise_error /does not have project/
end
end
context "when an array is provided" do
let(:include_content) { ["/local.gitlab-ci.yml"] }
- it "does not return any error" do
- expect { subject }.not_to raise_error
+ it "returns a validation error" do
+ expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, /does not have project/)
end
end
@@ -643,11 +643,18 @@ module Gitlab
let(:include_content) do
[
'https://gitlab.com/awesome-project/raw/master/.before-script-template.yml',
- '/templates/.after-script-template.yml',
{ template: 'Auto-DevOps.gitlab-ci.yml' }
]
end
+ before do
+ WebMock.stub_request(:get, 'https://gitlab.com/awesome-project/raw/master/.before-script-template.yml')
+ .to_return(
+ status: 200,
+ headers: { 'Content-Type' => 'application/json' },
+ body: 'prepare: { script: ls -al }')
+ end
+
it "does not return any error" do
expect { subject }.not_to raise_error
end