diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/ci/create_pipeline_service/dry_run_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/ci/create_pipeline_service/dry_run_spec.rb')
-rw-r--r-- | spec/services/ci/create_pipeline_service/dry_run_spec.rb | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/spec/services/ci/create_pipeline_service/dry_run_spec.rb b/spec/services/ci/create_pipeline_service/dry_run_spec.rb new file mode 100644 index 00000000000..93378df80f0 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/dry_run_spec.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::CreatePipelineService do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:admin) } + let(:ref) { 'refs/heads/master' } + let(:service) { described_class.new(project, user, { ref: ref }) } + + subject { service.execute(:push, dry_run: true) } + + before do + stub_ci_pipeline_yaml_file(config) + end + + describe 'dry run' do + shared_examples 'returns a non persisted pipeline' do + it 'does not persist the pipeline' do + expect(subject).not_to be_persisted + expect(subject.id).to be_nil + end + + it 'does not process the pipeline' do + expect(Ci::ProcessPipelineService).not_to receive(:new) + + subject + end + + it 'does not schedule merge request head pipeline update' do + expect(service).not_to receive(:schedule_head_pipeline_update) + + subject + end + end + + context 'when pipeline is valid' do + let(:config) { gitlab_ci_yaml } + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a valid pipeline' do + expect(subject.error_messages).to be_empty + expect(subject.yaml_errors).to be_nil + expect(subject.errors).to be_empty + end + end + + context 'when pipeline is not valid' do + context 'when there are syntax errors' do + let(:config) do + <<~YAML + rspec: + script: echo + something: wrong + YAML + end + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a pipeline with errors', :aggregate_failures do + error_message = 'jobs:rspec config contains unknown keys: something' + + expect(subject.error_messages.map(&:content)).to eq([error_message]) + expect(subject.errors).not_to be_empty + expect(subject.yaml_errors).to eq(error_message) + end + end + + context 'when there are logical errors' do + let(:config) do + <<~YAML + build: + script: echo + stage: build + needs: [test] + test: + script: echo + stage: test + YAML + end + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a pipeline with errors', :aggregate_failures do + error_message = 'build job: need test is not defined in prior stages' + + expect(subject.error_messages.map(&:content)).to eq([error_message]) + expect(subject.errors).not_to be_empty + end + end + + context 'when there are errors at the seeding stage' do + let(:config) do + <<~YAML + build: + stage: build + script: echo + rules: + - if: '$CI_MERGE_REQUEST_ID' + test: + stage: test + script: echo + needs: ['build'] + YAML + end + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a pipeline with errors', :aggregate_failures do + error_message = "test: needs 'build'" + + expect(subject.error_messages.map(&:content)).to eq([error_message]) + expect(subject.errors).not_to be_empty + end + end + end + end +end |