2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Status::Composite do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
before_all do
|
2020-07-28 23:09:34 +05:30
|
|
|
@statuses = Ci::HasStatus::STATUSES_ENUM.map do |status, idx|
|
2019-12-21 20:55:43 +05:30
|
|
|
[status, create(:ci_build, pipeline: pipeline, status: status, importing: true)]
|
|
|
|
end.to_h
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
@statuses_with_allow_failure = Ci::HasStatus::STATUSES_ENUM.map do |status, idx|
|
2019-12-21 20:55:43 +05:30
|
|
|
[status, create(:ci_build, pipeline: pipeline, status: status, allow_failure: true, importing: true)]
|
|
|
|
end.to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#status' do
|
2020-10-24 23:57:45 +05:30
|
|
|
using RSpec::Parameterized::TableSyntax
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
shared_examples 'compares status and warnings' do
|
|
|
|
let(:composite_status) do
|
2020-11-24 15:15:51 +05:30
|
|
|
described_class.new(all_statuses, dag: dag)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status and warnings?' do
|
|
|
|
expect(composite_status.status).to eq(result)
|
|
|
|
expect(composite_status.warnings?).to eq(has_warnings)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'allow_failure: false' do
|
2020-11-24 15:15:51 +05:30
|
|
|
where(:build_statuses, :dag, :result, :has_warnings) do
|
|
|
|
%i(skipped) | false | 'skipped' | false
|
|
|
|
%i(skipped success) | false | 'success' | false
|
|
|
|
%i(skipped success) | true | 'skipped' | false
|
|
|
|
%i(created) | false | 'created' | false
|
|
|
|
%i(preparing) | false | 'preparing' | false
|
|
|
|
%i(canceled success skipped) | false | 'canceled' | false
|
|
|
|
%i(canceled success skipped) | true | 'skipped' | false
|
|
|
|
%i(pending created skipped) | false | 'pending' | false
|
|
|
|
%i(pending created skipped success) | false | 'running' | false
|
|
|
|
%i(running created skipped success) | false | 'running' | false
|
|
|
|
%i(pending created skipped) | true | 'skipped' | false
|
|
|
|
%i(pending created skipped success) | true | 'skipped' | false
|
|
|
|
%i(running created skipped success) | true | 'skipped' | false
|
|
|
|
%i(success waiting_for_resource) | false | 'waiting_for_resource' | false
|
|
|
|
%i(success manual) | false | 'manual' | false
|
|
|
|
%i(success scheduled) | false | 'scheduled' | false
|
|
|
|
%i(created preparing) | false | 'preparing' | false
|
|
|
|
%i(created success pending) | false | 'running' | false
|
|
|
|
%i(skipped success failed) | false | 'failed' | false
|
|
|
|
%i(skipped success failed) | true | 'skipped' | false
|
|
|
|
%i(success manual) | true | 'pending' | false
|
|
|
|
%i(success failed created) | true | 'pending' | false
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let(:all_statuses) do
|
|
|
|
build_statuses.map { |status| @statuses[status] }
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it_behaves_like 'compares status and warnings'
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'allow_failure: true' do
|
2020-11-24 15:15:51 +05:30
|
|
|
where(:build_statuses, :dag, :result, :has_warnings) do
|
|
|
|
%i(manual) | false | 'skipped' | false
|
|
|
|
%i(skipped failed) | false | 'success' | true
|
|
|
|
%i(skipped failed) | true | 'skipped' | true
|
2021-04-17 20:07:23 +05:30
|
|
|
%i(success manual) | true | 'skipped' | false
|
|
|
|
%i(success manual) | false | 'success' | false
|
2020-11-24 15:15:51 +05:30
|
|
|
%i(created failed) | false | 'created' | true
|
|
|
|
%i(preparing manual) | false | 'preparing' | false
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let(:all_statuses) do
|
|
|
|
build_statuses.map { |status| @statuses_with_allow_failure[status] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'compares status and warnings'
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
context 'when FF ci_fix_pipeline_status_for_dag_needs_manual is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_fix_pipeline_status_for_dag_needs_manual: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
where(:build_statuses, :dag, :result, :has_warnings) do
|
|
|
|
%i(success manual) | true | 'pending' | false
|
|
|
|
%i(success manual) | false | 'success' | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let(:all_statuses) do
|
|
|
|
build_statuses.map { |status| @statuses_with_allow_failure[status] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'compares status and warnings'
|
|
|
|
end
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|