summaryrefslogtreecommitdiff
path: root/spec/models/ci/pipeline_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-08 06:08:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-08 06:08:50 +0000
commit6397f0322d3841d98d64e9c60bb84b94c40617d7 (patch)
treecc54eebf050e102dcf7394f5b94b7699148050df /spec/models/ci/pipeline_spec.rb
parent91ed938e3d17d385a08459915972d7e3f6b8468e (diff)
downloadgitlab-ce-6397f0322d3841d98d64e9c60bb84b94c40617d7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb104
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 09d6d661d81..18f3c4af08c 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1210,6 +1210,32 @@ describe Ci::Pipeline, :mailer do
end
end
+ context 'when pipeline is bridge triggered' do
+ before do
+ pipeline.source_bridge = create(:ci_bridge)
+ end
+
+ context 'when source bridge is dependent on pipeline status' do
+ before do
+ allow(pipeline.source_bridge).to receive(:dependent?).and_return(true)
+ end
+
+ it 'schedules the pipeline bridge worker' do
+ expect(::Ci::PipelineBridgeStatusWorker).to receive(:perform_async)
+
+ pipeline.succeed!
+ end
+ end
+
+ context 'when source bridge is not dependent on pipeline status' do
+ it 'does not schedule the pipeline bridge worker' do
+ expect(::Ci::PipelineBridgeStatusWorker).not_to receive(:perform_async)
+
+ pipeline.succeed!
+ end
+ end
+ end
+
def auto_devops_pipelines_completed_total(status)
Gitlab::Metrics.counter(:auto_devops_pipelines_completed_total, 'Number of completed auto devops pipelines').get(status: status)
end
@@ -2883,4 +2909,82 @@ describe Ci::Pipeline, :mailer do
end
end
end
+
+ describe 'upstream status interactions' do
+ context 'when a pipeline has an upstream status' do
+ context 'when an upstream status is a bridge' do
+ let(:bridge) { create(:ci_bridge, status: :pending) }
+
+ before do
+ create(:ci_sources_pipeline, pipeline: pipeline, source_job: bridge)
+ end
+
+ describe '#bridge_triggered?' do
+ it 'is a pipeline triggered by a bridge' do
+ expect(pipeline).to be_bridge_triggered
+ end
+ end
+
+ describe '#source_job' do
+ it 'has a correct source job' do
+ expect(pipeline.source_job).to eq bridge
+ end
+ end
+
+ describe '#source_bridge' do
+ it 'has a correct bridge source' do
+ expect(pipeline.source_bridge).to eq bridge
+ end
+ end
+
+ describe '#update_bridge_status!' do
+ it 'can update bridge status if it is running' do
+ pipeline.update_bridge_status!
+
+ expect(bridge.reload).to be_success
+ end
+
+ it 'can not update bridge status if is not active' do
+ bridge.success!
+
+ expect { pipeline.update_bridge_status! }
+ .to raise_error Ci::Pipeline::BridgeStatusError
+ end
+ end
+ end
+
+ context 'when an upstream status is a build' do
+ let(:build) { create(:ci_build) }
+
+ before do
+ create(:ci_sources_pipeline, pipeline: pipeline, source_job: build)
+ end
+
+ describe '#bridge_triggered?' do
+ it 'is a pipeline that has not been triggered by a bridge' do
+ expect(pipeline).not_to be_bridge_triggered
+ end
+ end
+
+ describe '#source_job' do
+ it 'has a correct source job' do
+ expect(pipeline.source_job).to eq build
+ end
+ end
+
+ describe '#source_bridge' do
+ it 'does not have a bridge source' do
+ expect(pipeline.source_bridge).to be_nil
+ end
+ end
+
+ describe '#update_bridge_status!' do
+ it 'can not update upstream job status' do
+ expect { pipeline.update_bridge_status! }
+ .to raise_error ArgumentError
+ end
+ end
+ end
+ end
+ end
end