summaryrefslogtreecommitdiff
path: root/spec/services/ci
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-03 18:08:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-03 18:08:16 +0000
commite9c2bf267862e22c0770cc7b3a1ed97a8b87a7fd (patch)
tree7b778e44f210132af1233ceb8801b388ac3519f5 /spec/services/ci
parent946771d0b016ae92b15a60bc3290a33b94191ffe (diff)
downloadgitlab-ce-e9c2bf267862e22c0770cc7b3a1ed97a8b87a7fd.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/ci')
-rw-r--r--spec/services/ci/create_cross_project_pipeline_service_spec.rb72
1 files changed, 68 insertions, 4 deletions
diff --git a/spec/services/ci/create_cross_project_pipeline_service_spec.rb b/spec/services/ci/create_cross_project_pipeline_service_spec.rb
index 09d44bcea0a..667ad532fb0 100644
--- a/spec/services/ci/create_cross_project_pipeline_service_spec.rb
+++ b/spec/services/ci/create_cross_project_pipeline_service_spec.rb
@@ -116,6 +116,28 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
expect(bridge.reload).to be_success
end
+ context 'when bridge job has already any downstream pipelines' do
+ before do
+ bridge.sourced_pipelines.create!(
+ source_pipeline: bridge.pipeline,
+ source_project: bridge.project,
+ project: bridge.project,
+ pipeline: create(:ci_pipeline, project: bridge.project)
+ )
+ end
+
+ it 'logs an error and exits' do
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_exception)
+ .with(
+ instance_of(Ci::CreateCrossProjectPipelineService::DuplicateDownstreamPipelineError),
+ bridge_id: bridge.id, project_id: bridge.project.id)
+ .and_call_original
+ expect(Ci::CreatePipelineService).not_to receive(:new)
+ expect(service.execute(bridge)).to be_nil
+ end
+ end
+
context 'when target ref is not specified' do
let(:trigger) do
{ trigger: { project: downstream_project.full_path } }
@@ -149,13 +171,11 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
expect(pipeline.source_bridge).to be_a ::Ci::Bridge
end
- it 'does not update bridge status when downstream pipeline gets processed' do
+ it 'updates the bridge status when downstream pipeline gets processed' do
pipeline = service.execute(bridge)
expect(pipeline.reload).to be_failed
- # TODO: This should change to failed once #198354 gets fixed.
- # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25706
- expect(bridge.reload).to be_pending
+ expect(bridge.reload).to be_failed
end
end
@@ -242,6 +262,22 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
it_behaves_like 'creates a child pipeline'
+ it 'updates the bridge job to success' do
+ expect { service.execute(bridge) }.to change { bridge.status }.to 'success'
+ end
+
+ context 'when bridge uses "depend" strategy' do
+ let(:trigger) do
+ {
+ trigger: { include: 'child-pipeline.yml', strategy: 'depend' }
+ }
+ end
+
+ it 'does not update the bridge job status' do
+ expect { service.execute(bridge) }.not_to change { bridge.status }
+ end
+ end
+
context 'when latest sha for the ref changed in the meantime' do
before do
upstream_project.repository.create_file(
@@ -298,6 +334,34 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
end
end
+ context 'when downstream pipeline creation errors out' do
+ let(:stub_config) { false }
+
+ before do
+ stub_ci_pipeline_yaml_file(YAML.dump(invalid: { yaml: 'error' }))
+ end
+
+ it 'creates only one new pipeline' do
+ expect { service.execute(bridge) }
+ .to change { Ci::Pipeline.count }.by(1)
+ end
+
+ it 'creates a new pipeline in the downstream project' do
+ pipeline = service.execute(bridge)
+
+ expect(pipeline.user).to eq bridge.user
+ expect(pipeline.project).to eq downstream_project
+ end
+
+ it 'drops the bridge' do
+ pipeline = service.execute(bridge)
+
+ expect(pipeline.reload).to be_failed
+ expect(bridge.reload).to be_failed
+ expect(bridge.failure_reason).to eq('downstream_pipeline_creation_failed')
+ end
+ end
+
context 'when bridge job has YAML variables defined' do
before do
bridge.yaml_variables = [{ key: 'BRIDGE', value: 'var', public: true }]