debian-mirror-gitlab/spec/lib/gitlab/ci/status/composite_spec.rb

77 lines
2.4 KiB
Ruby
Raw Normal View History

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
described_class.new(all_statuses)
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
where(:build_statuses, :result, :has_warnings) do
%i(skipped) | 'skipped' | false
%i(skipped success) | 'success' | false
%i(created) | 'created' | false
%i(preparing) | 'preparing' | false
%i(canceled success skipped) | 'canceled' | false
%i(pending created skipped) | 'pending' | false
%i(pending created skipped success) | 'running' | false
%i(running created skipped success) | 'running' | false
%i(success waiting_for_resource) | 'waiting_for_resource' | false
%i(success manual) | 'manual' | false
%i(success scheduled) | 'scheduled' | false
%i(created preparing) | 'preparing' | false
%i(created success pending) | 'running' | false
%i(skipped success failed) | 'failed' | false
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
where(:build_statuses, :result, :has_warnings) do
%i(manual) | 'skipped' | false
%i(skipped failed) | 'success' | true
%i(created failed) | 'created' | true
%i(preparing manual) | 'preparing' | 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
2019-12-21 20:55:43 +05:30
end
end