From 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Feb 2021 10:34:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-9-stable-ee --- .../cross_project_pipeline_spec.rb | 86 ++++++++++++++++++++++ .../custom_yaml_tags_spec.rb | 79 ++++++++++++++++++++ .../parent_child_pipeline_spec.rb | 50 +++++++++++++ .../ci/create_pipeline_service/rules_spec.rb | 14 ---- 4 files changed, 215 insertions(+), 14 deletions(-) create mode 100644 spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb create mode 100644 spec/services/ci/create_pipeline_service/custom_yaml_tags_spec.rb (limited to 'spec/services/ci/create_pipeline_service') 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 new file mode 100644 index 00000000000..9cf66dfceb0 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +require 'spec_helper' + +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(:user) { create(:user) } + + let(:service) do + described_class.new(upstream_project, user, ref: 'master') + end + + before do + upstream_project.add_developer(user) + downstram_project.add_developer(user) + create_gitlab_ci_yml(upstream_project, upstream_config) + create_gitlab_ci_yml(downstram_project, downstream_config) + end + + context 'with resource group', :aggregate_failures do + let(:upstream_config) do + <<~YAML + instrumentation_test: + stage: test + resource_group: iOS + trigger: + project: my-organization/downstream + strategy: depend + YAML + end + + let(:downstream_config) do + <<~YAML + test: + script: echo "Testing..." + YAML + end + + it 'creates bridge job with resource group' do + pipeline = create_pipeline! + + test = pipeline.statuses.find_by(name: 'instrumentation_test') + expect(pipeline).to be_created_successfully + expect(pipeline.triggered_pipelines).not_to be_exist + expect(upstream_project.resource_groups.count).to eq(1) + expect(test).to be_a Ci::Bridge + expect(test).to be_waiting_for_resource + expect(test.resource_group.key).to eq('iOS') + end + + context 'when sidekiq processes the job', :sidekiq_inline do + it 'transitions to pending status and triggers a downstream pipeline' do + pipeline = create_pipeline! + + test = pipeline.statuses.find_by(name: 'instrumentation_test') + expect(test).to be_pending + expect(pipeline.triggered_pipelines.count).to eq(1) + end + + context 'when the resource is occupied by the other bridge' do + before do + resource_group = create(:ci_resource_group, project: upstream_project, key: 'iOS') + resource_group.assign_resource_to(create(:ci_build, project: upstream_project)) + end + + it 'stays waiting for resource' do + pipeline = create_pipeline! + + test = pipeline.statuses.find_by(name: 'instrumentation_test') + expect(test).to be_waiting_for_resource + expect(pipeline.triggered_pipelines.count).to eq(0) + end + end + end + end + + def create_pipeline! + service.execute(:push) + end + + def create_gitlab_ci_yml(project, content) + project.repository.create_file(user, '.gitlab-ci.yml', content, branch_name: 'master', message: 'test') + end +end 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 new file mode 100644 index 00000000000..4cf52223e38 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/custom_yaml_tags_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Ci::CreatePipelineService do + describe '!reference tags' 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) } + + before do + stub_ci_pipeline_yaml_file(config) + end + + context 'with valid config' do + let(:config) do + <<~YAML + .job-1: + script: + - echo doing step 1 of job 1 + + .job-2: + before_script: + - ls + script: !reference [.job-1, script] + + job: + before_script: !reference [.job-2, before_script] + script: + - echo doing my first step + - !reference [.job-2, script] + - echo doing my last step + YAML + end + + it 'creates a pipeline' do + expect(pipeline).to be_persisted + expect(pipeline.builds.first.options).to match(a_hash_including({ + 'before_script' => ['ls'], + 'script' => [ + 'echo doing my first step', + 'echo doing step 1 of job 1', + 'echo doing my last step' + ] + })) + end + end + + context 'with invalid config' do + let(:config) do + <<~YAML + job-1: + script: + - echo doing step 1 of job 1 + - !reference [job-3, script] + + job-2: + script: + - echo doing step 1 of job 2 + - !reference [job-3, script] + + job-3: + script: + - echo doing step 1 of job 3 + - !reference [job-1, script] + YAML + end + + it 'creates a pipeline without builds' do + expect(pipeline).to be_persisted + expect(pipeline.builds).to be_empty + expect(pipeline.yaml_errors).to eq("!reference [\"job-3\", \"script\"] is part of a circular chain") + 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 8df9b0c3e60..a3818937113 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 @@ -76,6 +76,56 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do } end end + + context 'with resource group' do + let(:config) do + <<~YAML + instrumentation_test: + stage: test + resource_group: iOS + trigger: + include: path/to/child.yml + strategy: depend + YAML + end + + it 'creates bridge job with resource group', :aggregate_failures do + pipeline = create_pipeline! + + test = pipeline.statuses.find_by(name: 'instrumentation_test') + expect(pipeline).to be_created_successfully + expect(pipeline.triggered_pipelines).not_to be_exist + expect(project.resource_groups.count).to eq(1) + expect(test).to be_a Ci::Bridge + expect(test).to be_waiting_for_resource + expect(test.resource_group.key).to eq('iOS') + end + + context 'when sidekiq processes the job', :sidekiq_inline do + it 'transitions to pending status and triggers a downstream pipeline' do + pipeline = create_pipeline! + + test = pipeline.statuses.find_by(name: 'instrumentation_test') + expect(test).to be_pending + expect(pipeline.triggered_pipelines.count).to eq(1) + end + + context 'when the resource is occupied by the other bridge' do + before do + resource_group = create(:ci_resource_group, project: project, key: 'iOS') + resource_group.assign_resource_to(create(:ci_build, project: project)) + end + + it 'stays waiting for resource' do + pipeline = create_pipeline! + + test = pipeline.statuses.find_by(name: 'instrumentation_test') + expect(test).to be_waiting_for_resource + expect(pipeline.triggered_pipelines.count).to eq(0) + end + end + end + end end describe 'child pipeline triggers' do diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb index ac6c4c188e4..04ecac6a85a 100644 --- a/spec/services/ci/create_pipeline_service/rules_spec.rb +++ b/spec/services/ci/create_pipeline_service/rules_spec.rb @@ -145,20 +145,6 @@ RSpec.describe Ci::CreatePipelineService do expect(find_job('job-2').options.dig(:allow_failure_criteria)).to be_nil expect(find_job('job-3').options.dig(:allow_failure_criteria, :exit_codes)).to eq([42]) end - - context 'with ci_allow_failure_with_exit_codes disabled' do - before do - stub_feature_flags(ci_allow_failure_with_exit_codes: false) - end - - it 'does not persist allow_failure_criteria' do - expect(pipeline).to be_persisted - - expect(find_job('job-1').options.key?(:allow_failure_criteria)).to be_falsey - expect(find_job('job-2').options.key?(:allow_failure_criteria)).to be_falsey - expect(find_job('job-3').options.key?(:allow_failure_criteria)).to be_falsey - end - end end context 'if:' do -- cgit v1.2.1