2016-03-23 06:24:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
describe Gitlab::Badge::Pipeline::Status do
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-03-23 06:24:18 -04:00
|
|
|
let(:sha) { project.commit.sha }
|
2016-04-01 07:03:14 -04:00
|
|
|
let(:branch) { 'master' }
|
|
|
|
let(:badge) { described_class.new(project, branch) }
|
2016-03-23 06:24:18 -04:00
|
|
|
|
2016-08-11 05:16:14 -04:00
|
|
|
describe '#entity' do
|
2017-07-19 07:08:47 -04:00
|
|
|
it 'always says pipeline' do
|
|
|
|
expect(badge.entity).to eq 'pipeline'
|
2016-08-11 05:16:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#template' do
|
|
|
|
it 'returns badge template' do
|
2017-07-19 07:08:47 -04:00
|
|
|
expect(badge.template.key_text).to eq 'pipeline'
|
2016-08-11 05:16:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-28 08:35:02 -04:00
|
|
|
describe '#metadata' do
|
|
|
|
it 'returns badge metadata' do
|
2017-07-19 07:08:47 -04:00
|
|
|
expect(badge.metadata.image_url).to include 'badges/master/pipeline.svg'
|
2016-04-01 07:03:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
context 'pipeline exists' do
|
|
|
|
let!(:pipeline) { create_pipeline(project, sha, branch) }
|
2016-03-29 02:55:49 -04:00
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
context 'pipeline success' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-07-19 07:08:47 -04:00
|
|
|
pipeline.success!
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
|
2016-07-28 08:58:53 -04:00
|
|
|
describe '#status' do
|
|
|
|
it 'is successful' do
|
|
|
|
expect(badge.status).to eq 'success'
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
context 'pipeline failed' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-07-19 07:08:47 -04:00
|
|
|
pipeline.drop!
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-03-23 06:24:18 -04:00
|
|
|
|
2016-07-28 08:58:53 -04:00
|
|
|
describe '#status' do
|
|
|
|
it 'failed' do
|
|
|
|
expect(badge.status).to eq 'failed'
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-09 07:33:19 -04:00
|
|
|
|
|
|
|
context 'when outdated pipeline for given ref exists' do
|
|
|
|
before do
|
2017-07-19 07:08:47 -04:00
|
|
|
pipeline.success!
|
2016-08-09 07:33:19 -04:00
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
old_pipeline = create_pipeline(project, '11eeffdd', branch)
|
|
|
|
old_pipeline.drop!
|
2016-08-09 07:33:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not take outdated pipeline into account' do
|
|
|
|
expect(badge.status).to eq 'success'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when multiple pipelines exist for given sha' do
|
|
|
|
before do
|
2017-07-19 07:08:47 -04:00
|
|
|
pipeline.drop!
|
2016-08-09 07:33:19 -04:00
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
new_pipeline = create_pipeline(project, sha, branch)
|
|
|
|
new_pipeline.success!
|
2016-08-09 07:33:19 -04:00
|
|
|
end
|
|
|
|
|
2016-11-24 04:00:37 -05:00
|
|
|
it 'does not take outdated pipeline into account' do
|
|
|
|
expect(badge.status).to eq 'success'
|
2016-08-09 07:33:19 -04:00
|
|
|
end
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'build does not exist' do
|
2016-07-28 08:58:53 -04:00
|
|
|
describe '#status' do
|
|
|
|
it 'is unknown' do
|
|
|
|
expect(badge.status).to eq 'unknown'
|
|
|
|
end
|
2016-03-23 06:24:18 -04:00
|
|
|
end
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
def create_pipeline(project, sha, branch)
|
2016-08-11 09:22:35 -04:00
|
|
|
pipeline = create(:ci_empty_pipeline,
|
|
|
|
project: project,
|
|
|
|
sha: sha,
|
|
|
|
ref: branch)
|
2016-06-01 07:11:28 -04:00
|
|
|
|
2016-07-19 07:23:14 -04:00
|
|
|
create(:ci_build, pipeline: pipeline, stage: 'notify')
|
2016-06-01 07:11:28 -04:00
|
|
|
end
|
2016-03-23 06:24:18 -04:00
|
|
|
end
|