Commit 24d10939 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '213666-display-bridge-failure-reason' into 'master'

Implement showing CI bridge error messages

See merge request gitlab-org/gitlab!29123
parents 18f6ea6c 259b93dd
---
title: Implement showing CI bridge error messages
merge_request: 29123
author:
type: other
...@@ -5,6 +5,10 @@ module Gitlab ...@@ -5,6 +5,10 @@ module Gitlab
module Status module Status
module Bridge module Bridge
class Factory < Status::Factory class Factory < Status::Factory
def self.extended_statuses
[Status::Bridge::Failed]
end
def self.common_helpers def self.common_helpers
Status::Bridge::Common Status::Bridge::Common
end end
......
# frozen_string_literal: true
module Gitlab
module Ci
module Status
module Bridge
class Failed < Status::Build::Failed
end
end
end
end
end
...@@ -7,7 +7,7 @@ FactoryBot.define do ...@@ -7,7 +7,7 @@ FactoryBot.define do
stage_idx { 0 } stage_idx { 0 }
ref { 'master' } ref { 'master' }
tag { false } tag { false }
created_at { 'Di 29. Okt 09:50:00 CET 2013' } created_at { '2013-10-29 09:50:00 CET' }
status { :created } status { :created }
scheduling_type { 'stage' } scheduling_type { 'stage' }
...@@ -39,5 +39,19 @@ FactoryBot.define do ...@@ -39,5 +39,19 @@ FactoryBot.define do
) )
end end
end end
trait :started do
started_at { '2013-10-29 09:51:28 CET' }
end
trait :finished do
started
finished_at { '2013-10-29 09:53:28 CET' }
end
trait :failed do
finished
status { 'failed' }
end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Status::Bridge::Factory do
let(:user) { create(:user) }
let(:project) { bridge.project }
let(:status) { factory.fabricate! }
let(:factory) { described_class.new(bridge, user) }
before do
stub_not_protect_default_branch
project.add_developer(user)
end
context 'when bridge is created' do
let(:bridge) { create(:ci_bridge) }
it 'matches correct core status' do
expect(factory.core_status).to be_a Gitlab::Ci::Status::Created
end
it 'fabricates status with correct details' do
expect(status.text).to eq s_('CiStatusText|created')
expect(status.icon).to eq 'status_created'
expect(status.favicon).to eq 'favicon_status_created'
expect(status.label).to be_nil
expect(status).not_to have_details
expect(status).not_to have_action
end
end
context 'when bridge is failed' do
let(:bridge) { create(:ci_bridge, :failed) }
it 'matches correct core status' do
expect(factory.core_status).to be_a Gitlab::Ci::Status::Failed
end
it 'matches correct extended statuses' do
expect(factory.extended_statuses)
.to eq [Gitlab::Ci::Status::Bridge::Failed]
end
it 'fabricates a failed bridge status' do
expect(status).to be_a Gitlab::Ci::Status::Bridge::Failed
end
it 'fabricates status with correct details' do
expect(status.text).to eq s_('CiStatusText|failed')
expect(status.icon).to eq 'status_failed'
expect(status.favicon).to eq 'favicon_status_failed'
expect(status.label).to be_nil
expect(status.status_tooltip).to eq "#{s_('CiStatusText|failed')} - (unknown failure)"
expect(status).not_to have_details
expect(status).not_to have_action
end
context 'failed with downstream_pipeline_creation_failed' do
before do
bridge.failure_reason = 'downstream_pipeline_creation_failed'
end
it 'fabricates correct status_tooltip' do
expect(status.status_tooltip).to eq(
"#{s_('CiStatusText|failed')} - (downstream pipeline can not be created)"
)
end
end
end
end
...@@ -475,5 +475,45 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -475,5 +475,45 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
expect(bridge.failure_reason).to eq 'insufficient_bridge_permissions' expect(bridge.failure_reason).to eq 'insufficient_bridge_permissions'
end end
end end
context 'when there is no such branch in downstream project' do
let(:trigger) do
{
trigger: {
project: downstream_project.full_path,
branch: 'invalid_branch'
}
}
end
it 'does not create a pipeline and drops the bridge' do
service.execute(bridge)
expect(bridge.reload).to be_failed
expect(bridge.failure_reason).to eq('downstream_pipeline_creation_failed')
end
end
context 'when downstream pipeline has a branch rule and does not satisfy' do
before do
stub_ci_pipeline_yaml_file(config)
end
let(:config) do
<<-EOY
hello:
script: echo world
only:
- invalid_branch
EOY
end
it 'does not create a pipeline and drops the bridge' do
service.execute(bridge)
expect(bridge.reload).to be_failed
expect(bridge.failure_reason).to eq('downstream_pipeline_creation_failed')
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment