diff options
Diffstat (limited to 'spec/services/ci/create_pipeline_service')
16 files changed, 113 insertions, 18 deletions
diff --git a/spec/services/ci/create_pipeline_service/cache_spec.rb b/spec/services/ci/create_pipeline_service/cache_spec.rb index f9767a794db..f5f162e4578 100644 --- a/spec/services/ci/create_pipeline_service/cache_spec.rb +++ b/spec/services/ci/create_pipeline_service/cache_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/master' } let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } let(:job) { pipeline.builds.find_by(name: 'job') } before do 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 index a42770aae20..c69c91593ae 100644 --- 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 @@ -10,7 +10,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/master' } let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } before do stub_ci_pipeline_yaml_file(config) diff --git a/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb b/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb index b3b8e34dd8e..e1d60ed57ef 100644 --- a/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb +++ b/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do let_it_be(:group) { create(:group, name: 'my-organization') } let(:upstream_project) { create(:project, :repository, name: 'upstream', group: group) } - let(:downstram_project) { create(:project, :repository, name: 'downstream', group: group) } + let(:downstream_project) { create(:project, :repository, name: 'downstream', group: group) } let(:user) { create(:user) } let(:service) do @@ -15,9 +15,9 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do before do upstream_project.add_developer(user) - downstram_project.add_developer(user) + downstream_project.add_developer(user) create_gitlab_ci_yml(upstream_project, upstream_config) - create_gitlab_ci_yml(downstram_project, downstream_config) + create_gitlab_ci_yml(downstream_project, downstream_config) end context 'with resource group', :aggregate_failures do @@ -79,7 +79,7 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do end def create_pipeline! - service.execute(:push) + service.execute(:push).payload end def create_gitlab_ci_yml(project, content) 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 42c3f52541b..f150a4f8b51 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 @@ -11,7 +11,7 @@ RSpec.describe Ci::CreatePipelineService do let(:upstream_pipeline) { create(:ci_pipeline, project: project) } let(:bridge) { create(:ci_bridge, pipeline: upstream_pipeline) } - subject { service.execute(:push, bridge: bridge) } + subject { service.execute(:push, bridge: bridge).payload } context 'custom config content' do let(:bridge) do diff --git a/spec/services/ci/create_pipeline_service/custom_yaml_tags_spec.rb b/spec/services/ci/create_pipeline_service/custom_yaml_tags_spec.rb index 5dceb9f57f0..026111d59f1 100644 --- a/spec/services/ci/create_pipeline_service/custom_yaml_tags_spec.rb +++ b/spec/services/ci/create_pipeline_service/custom_yaml_tags_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/master' } let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } before do stub_ci_pipeline_yaml_file(config) diff --git a/spec/services/ci/create_pipeline_service/dry_run_spec.rb b/spec/services/ci/create_pipeline_service/dry_run_spec.rb index 01df7772eef..ae43c63b516 100644 --- a/spec/services/ci/create_pipeline_service/dry_run_spec.rb +++ b/spec/services/ci/create_pipeline_service/dry_run_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/master' } let(:service) { described_class.new(project, user, { ref: ref }) } - subject { service.execute(:push, dry_run: true) } + subject { service.execute(:push, dry_run: true).payload } before do stub_ci_pipeline_yaml_file(config) diff --git a/spec/services/ci/create_pipeline_service/environment_spec.rb b/spec/services/ci/create_pipeline_service/environment_spec.rb index e77591298ad..43b5220334c 100644 --- a/spec/services/ci/create_pipeline_service/environment_spec.rb +++ b/spec/services/ci/create_pipeline_service/environment_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Ci::CreatePipelineService do end describe '#execute' do - subject { service.execute(:push) } + subject { service.execute(:push).payload } context 'with deployment tier' do before do diff --git a/spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb b/spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb index df881c1ac8f..9add096d782 100644 --- a/spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb +++ b/spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Ci::CreatePipelineService do let_it_be(:user) { create(:user) } let(:service) { described_class.new(project, user, ref: 'master') } - let(:pipeline) { service.execute(:push) } + let(:pipeline) { service.execute(:push).payload } let(:job) { pipeline.builds.find_by(name: 'job') } before do diff --git a/spec/services/ci/create_pipeline_service/include_spec.rb b/spec/services/ci/create_pipeline_service/include_spec.rb new file mode 100644 index 00000000000..46271ee36c0 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/include_spec.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::CreatePipelineService do + context 'include:' do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { project.owner } + + let(:ref) { 'refs/heads/master' } + let(:source) { :push } + let(:service) { described_class.new(project, user, { ref: ref }) } + let(:pipeline) { service.execute(source).payload } + + let(:file_location) { 'spec/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml' } + + before do + allow(project.repository) + .to receive(:blob_data_at).with(project.commit.id, '.gitlab-ci.yml') + .and_return(config) + + allow(project.repository) + .to receive(:blob_data_at).with(project.commit.id, file_location) + .and_return(File.read(Rails.root.join(file_location))) + end + + context 'with a local file' do + let(:config) do + <<~EOY + include: #{file_location} + job: + script: exit 0 + EOY + end + + it 'includes the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') + end + end + + context 'with a local file with rules' do + let(:config) do + <<~EOY + include: + - local: #{file_location} + rules: + - if: $CI_PROJECT_ID == "#{project_id}" + job: + script: exit 0 + EOY + end + + context 'when the rules matches' do + let(:project_id) { project.id } + + it 'includes the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') + end + + context 'when the FF ci_include_rules is disabled' do + before do + stub_feature_flags(ci_include_rules: false) + end + + it 'includes the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') + end + end + end + + context 'when the rules does not match' do + let(:project_id) { non_existing_record_id } + + it 'does not include the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job') + end + + context 'when the FF ci_include_rules is disabled' do + before do + stub_feature_flags(ci_include_rules: false) + end + + it 'includes the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') + end + end + end + end + end +end diff --git a/spec/services/ci/create_pipeline_service/merge_requests_spec.rb b/spec/services/ci/create_pipeline_service/merge_requests_spec.rb index e5347faed6a..a1f85faa69f 100644 --- a/spec/services/ci/create_pipeline_service/merge_requests_spec.rb +++ b/spec/services/ci/create_pipeline_service/merge_requests_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/feature' } let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } before do stub_ci_pipeline_yaml_file <<-EOS diff --git a/spec/services/ci/create_pipeline_service/needs_spec.rb b/spec/services/ci/create_pipeline_service/needs_spec.rb index d096db10d0b..9070d86f7f6 100644 --- a/spec/services/ci/create_pipeline_service/needs_spec.rb +++ b/spec/services/ci/create_pipeline_service/needs_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/master' } let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } before do stub_ci_pipeline_yaml_file(config) diff --git a/spec/services/ci/create_pipeline_service/parallel_spec.rb b/spec/services/ci/create_pipeline_service/parallel_spec.rb index 5e34a67d376..6b455bf4874 100644 --- a/spec/services/ci/create_pipeline_service/parallel_spec.rb +++ b/spec/services/ci/create_pipeline_service/parallel_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Ci::CreatePipelineService do let_it_be(:user) { project.owner } let(:service) { described_class.new(project, user, { ref: 'master' }) } - let(:pipeline) { service.execute(:push) } + let(:pipeline) { service.execute(:push).payload } before do stub_ci_pipeline_yaml_file(config) diff --git a/spec/services/ci/create_pipeline_service/parameter_content_spec.rb b/spec/services/ci/create_pipeline_service/parameter_content_spec.rb index 94500a550c6..761504ffb58 100644 --- a/spec/services/ci/create_pipeline_service/parameter_content_spec.rb +++ b/spec/services/ci/create_pipeline_service/parameter_content_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Ci::CreatePipelineService do describe '#execute' do context 'when source is a dangling build' do - subject { service.execute(:ondemand_dast_scan, content: content) } + subject { service.execute(:ondemand_dast_scan, content: content).payload } context 'parameter config content' do it 'creates a pipeline' do 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 7a6535ed3fa..6eb1315fff4 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 @@ -369,6 +369,6 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do end def create_pipeline! - service.execute(:push) + service.execute(:push).payload end end 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 c84d9a53973..5e34eeb99db 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 @@ -8,7 +8,7 @@ RSpec.describe Ci::CreatePipelineService do let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } let(:config) do <<~YAML diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb index acdf38bbc13..d0915f099de 100644 --- a/spec/services/ci/create_pipeline_service/rules_spec.rb +++ b/spec/services/ci/create_pipeline_service/rules_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref) { 'refs/heads/master' } let(:source) { :push } let(:service) { described_class.new(project, user, { ref: ref }) } - let(:pipeline) { service.execute(source) } + let(:pipeline) { service.execute(source).payload } let(:build_names) { pipeline.builds.pluck(:name) } context 'job:rules' do |