diff options
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 104 | ||||
-rw-r--r-- | spec/models/ci/sources/pipeline_spec.rb | 1 |
2 files changed, 105 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 diff --git a/spec/models/ci/sources/pipeline_spec.rb b/spec/models/ci/sources/pipeline_spec.rb index 63bee5bfb55..5023747b487 100644 --- a/spec/models/ci/sources/pipeline_spec.rb +++ b/spec/models/ci/sources/pipeline_spec.rb @@ -8,6 +8,7 @@ describe Ci::Sources::Pipeline do it { is_expected.to belong_to(:source_project) } it { is_expected.to belong_to(:source_job) } + it { is_expected.to belong_to(:source_bridge) } it { is_expected.to belong_to(:source_pipeline) } it { is_expected.to validate_presence_of(:project) } |