Implement pipeline status factory with extended status
This commit is contained in:
parent
b86d8afe23
commit
d28f5e776b
2 changed files with 76 additions and 0 deletions
39
lib/gitlab/ci/status/pipeline/factory.rb
Normal file
39
lib/gitlab/ci/status/pipeline/factory.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Gitlab
|
||||
module Ci
|
||||
module Status
|
||||
module Pipeline
|
||||
class Factory
|
||||
EXTENDED_STATUSES = [Pipeline::SuccessWithWarnings]
|
||||
|
||||
def initialize(pipeline)
|
||||
@pipeline = pipeline
|
||||
@status = pipeline.status || :created
|
||||
end
|
||||
|
||||
def fabricate!
|
||||
if extended_status
|
||||
extended_status.new(core_status)
|
||||
else
|
||||
core_status
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def core_status
|
||||
Gitlab::Ci::Status
|
||||
.const_get(@status.capitalize)
|
||||
.new(@pipeline)
|
||||
.extend(Status::Pipeline::Common)
|
||||
end
|
||||
|
||||
def extended_status
|
||||
@extended ||= EXTENDED_STATUSES.find do |status|
|
||||
status.matches?(@pipeline)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
37
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
Normal file
37
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Ci::Status::Pipeline::Factory do
|
||||
subject do
|
||||
described_class.new(pipeline)
|
||||
end
|
||||
|
||||
context 'when pipeline has a core status' do
|
||||
HasStatus::AVAILABLE_STATUSES.each do |core_status|
|
||||
context "when core status is #{core_status}" do
|
||||
let(:pipeline) do
|
||||
create(:ci_pipeline, status: core_status)
|
||||
end
|
||||
|
||||
it "fabricates a core status #{core_status}" do
|
||||
expect(subject.fabricate!)
|
||||
.to be_a Gitlab::Ci::Status.const_get(core_status.capitalize)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when pipeline has warnings' do
|
||||
let(:pipeline) do
|
||||
create(:ci_pipeline, status: :success)
|
||||
end
|
||||
|
||||
before do
|
||||
create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline)
|
||||
end
|
||||
|
||||
it 'fabricates extended "success with warnings" status' do
|
||||
expect(subject.fabricate!)
|
||||
.to be_a Gitlab::Ci::Status::Pipeline::SuccessWithWarnings
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue