diff options
Diffstat (limited to 'spec/services/ci/create_pipeline_service')
8 files changed, 182 insertions, 6 deletions
diff --git a/spec/services/ci/create_pipeline_service/cache_spec.rb b/spec/services/ci/create_pipeline_service/cache_spec.rb index 4e0567132ff..614e46f1b1a 100644 --- a/spec/services/ci/create_pipeline_service/cache_spec.rb +++ b/spec/services/ci/create_pipeline_service/cache_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::CreatePipelineService do +RSpec.describe Ci::CreatePipelineService do context 'cache' do let(:user) { create(:admin) } let(:ref) { 'refs/heads/master' } diff --git a/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb b/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb new file mode 100644 index 00000000000..16205529f1c --- /dev/null +++ b/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::CreatePipelineService do + describe 'creation errors and warnings' do + let_it_be(:user) { create(:admin) } + let_it_be(:project) { create(:project, :repository, creator: user) } + + let(:ref) { 'refs/heads/master' } + let(:source) { :push } + let(:service) { described_class.new(project, user, { ref: ref }) } + let(:pipeline) { service.execute(source) } + + before do + stub_ci_pipeline_yaml_file(config) + stub_feature_flags(ci_raise_job_rules_without_workflow_rules_warning: true) + end + + context 'when created successfully' do + context 'when warnings are raised' do + let(:config) do + <<~YAML + test: + script: rspec + rules: + - if: '$CI_COMMIT_BRANCH' + YAML + end + + it 'contains only warnings' do + expect(pipeline.error_messages.map(&:content)).to be_empty + + expect(pipeline.warning_messages.map(&:content)).to contain_exactly( + 'jobs:test uses `rules` without defining `workflow:rules`' + ) + end + + context 'when feature flag is disabled for the particular warning' do + before do + stub_feature_flags(ci_raise_job_rules_without_workflow_rules_warning: false) + end + + it 'does not contain warnings' do + expect(pipeline.error_messages.map(&:content)).to be_empty + + expect(pipeline.warning_messages.map(&:content)).to be_empty + end + end + end + + context 'when no warnings are raised' do + let(:config) do + <<~YAML + test: + script: rspec + YAML + end + + it 'contains no warnings' do + expect(pipeline.error_messages).to be_empty + + expect(pipeline.warning_messages).to be_empty + end + end + end + + context 'when failed to create the pipeline' do + context 'when warnings are raised' do + let(:config) do + <<~YAML + build: + stage: build + script: echo + needs: [test] + test: + stage: test + script: echo + rules: + - if: '$CI_COMMIT_BRANCH' + YAML + end + + it 'contains both errors and warnings' do + error_message = 'build job: need test is not defined in prior stages' + warning_message = 'jobs:test uses `rules` without defining `workflow:rules`' + + expect(pipeline.yaml_errors).to eq(error_message) + expect(pipeline.error_messages.map(&:content)).to contain_exactly(error_message) + expect(pipeline.errors.full_messages).to contain_exactly(error_message) + + expect(pipeline.warning_messages.map(&:content)).to contain_exactly(warning_message) + end + end + + context 'when no warnings are raised' do + let(:config) do + <<~YAML + invalid: yaml + YAML + end + + it 'contains only errors' do + error_message = 'root config contains unknown keys: invalid' + expect(pipeline.yaml_errors).to eq(error_message) + expect(pipeline.error_messages.map(&:content)).to contain_exactly(error_message) + expect(pipeline.errors.full_messages).to contain_exactly(error_message) + + expect(pipeline.warning_messages).to be_empty + end + end + end + end +end diff --git a/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb b/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb index 5980260a08a..122870e0f3a 100644 --- a/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb +++ b/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Ci::CreatePipelineService do +RSpec.describe Ci::CreatePipelineService do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:admin) } let(:ref) { 'refs/heads/master' } diff --git a/spec/services/ci/create_pipeline_service/needs_spec.rb b/spec/services/ci/create_pipeline_service/needs_spec.rb index 17b9cf80cc1..915dc46d664 100644 --- a/spec/services/ci/create_pipeline_service/needs_spec.rb +++ b/spec/services/ci/create_pipeline_service/needs_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::CreatePipelineService do +RSpec.describe Ci::CreatePipelineService do context 'needs' do let_it_be(:user) { create(:admin) } let_it_be(:project) { create(:project, :repository, creator: user) } diff --git a/spec/services/ci/create_pipeline_service/parameter_content_spec.rb b/spec/services/ci/create_pipeline_service/parameter_content_spec.rb new file mode 100644 index 00000000000..5157574ea04 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/parameter_content_spec.rb @@ -0,0 +1,62 @@ +# 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(:service) { described_class.new(project, user, { ref: 'refs/heads/master' }) } + let(:content) do + <<~EOY + --- + stages: + - dast + + variables: + DAST_VERSION: 1 + SECURE_ANALYZERS_PREFIX: "registry.gitlab.com/gitlab-org/security-products/analyzers" + + dast: + stage: dast + image: + name: "$SECURE_ANALYZERS_PREFIX/dast:$DAST_VERSION" + variables: + GIT_STRATEGY: none + script: + - /analyze + EOY + end + + describe '#execute' do + context 'when source is a dangling build' do + subject { service.execute(:ondemand_dast_scan, content: content) } + + context 'parameter config content' do + it 'creates a pipeline' do + expect(subject).to be_persisted + end + + it 'creates builds with the correct names' do + expect(subject.builds.pluck(:name)).to match_array %w[dast] + end + + it 'creates stages with the correct names' do + expect(subject.stages.pluck(:name)).to match_array %w[dast] + end + + it 'sets the correct config source' do + expect(subject.config_source).to eq 'parameter_source' + end + end + end + + context 'when source is not a dangling build' do + subject { service.execute(:web, content: content) } + + it 'raises an exception' do + klass = Gitlab::Ci::Pipeline::Chain::Config::Content::Parameter::UnsupportedSourceError + expect { subject }.to raise_error(klass) + end + end + end +end diff --git a/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb b/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb index a76e83f2d60..016a5dfd18b 100644 --- a/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb +++ b/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::CreatePipelineService, '#execute' do +RSpec.describe Ci::CreatePipelineService, '#execute' do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } let(:ref_name) { 'master' } diff --git a/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb b/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb index 2b11b98f58c..00a2dd74968 100644 --- a/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb +++ b/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Ci::CreatePipelineService do +RSpec.describe Ci::CreatePipelineService do describe '.pre/.post stages' do let_it_be(:user) { create(:admin) } let_it_be(:project) { create(:project, :repository, creator: user) } diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb index 713d230731b..1a1fa6e8f5d 100644 --- a/spec/services/ci/create_pipeline_service/rules_spec.rb +++ b/spec/services/ci/create_pipeline_service/rules_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Ci::CreatePipelineService do +RSpec.describe Ci::CreatePipelineService do let(:user) { create(:admin) } let(:ref) { 'refs/heads/master' } let(:source) { :push } |