Improve Ci::Status::Build specs
This commit is contained in:
parent
8ce4bf20e7
commit
2ebba1ff33
|
@ -4,13 +4,13 @@ module Gitlab
|
|||
module Build
|
||||
class Failed < Status::Extended
|
||||
REASONS = {
|
||||
'unknown_failure' => 'unknown failure',
|
||||
'script_failure' => 'script failure',
|
||||
'api_failure' => 'API failure',
|
||||
'stuck_or_timeout_failure' => 'stuck or timeout failure',
|
||||
'runner_system_failure' => 'runner system failure',
|
||||
'missing_dependency_failure' => 'missing dependency failure',
|
||||
# COMMENTED to check if CI fails: 'runner_unsupported' => 'unsuported runner',
|
||||
unknown_failure: 'unknown failure',
|
||||
script_failure: 'script failure',
|
||||
api_failure: 'API failure',
|
||||
stuck_or_timeout_failure: 'stuck or timeout failure',
|
||||
runner_system_failure: 'runner system failure',
|
||||
missing_dependency_failure: 'missing dependency failure',
|
||||
runner_unsupported: 'Your runner is outdated, please upgrade your runner'
|
||||
}.freeze
|
||||
|
||||
def status_tooltip
|
||||
|
@ -32,7 +32,11 @@ module Gitlab
|
|||
end
|
||||
|
||||
def description
|
||||
"<br> (#{REASONS[subject.failure_reason]})"
|
||||
"<br> (#{failure_reason_message})"
|
||||
end
|
||||
|
||||
def failure_reason_message
|
||||
REASONS.fetch(subject.failure_reason.to_sym)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,4 +80,31 @@ describe Gitlab::Ci::Status::Build::Failed do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'covers all failure reasons' do
|
||||
let(:status) { Gitlab::Ci::Status::Failed.new(build, user) }
|
||||
let(:tooltip) { subject.status_tooltip }
|
||||
|
||||
CommitStatus.failure_reasons.keys.each do |failure_reason|
|
||||
context failure_reason do
|
||||
before do
|
||||
build.failure_reason = failure_reason
|
||||
end
|
||||
|
||||
it "is a valid status" do
|
||||
expect { tooltip }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid failure message' do
|
||||
before do
|
||||
expect(build).to receive(:failure_reason) { 'invalid failure message' }
|
||||
end
|
||||
|
||||
it "is an invalid status" do
|
||||
expect { tooltip }.to raise_error(/key not found:/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue