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

64 lines
2.1 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
shared_examples 'compares composite with SQL status' do
it 'returns exactly the same result' do
builds = Ci::Build.where(id: all_statuses)
expect(composite_status.status).to eq(builds.legacy_status)
expect(composite_status.warnings?).to eq(builds.failed_but_allowed.any?)
end
end
shared_examples 'validate all combinations' do |perms|
2020-07-28 23:09:34 +05:30
Ci::HasStatus::STATUSES_ENUM.keys.combination(perms).each do |statuses|
2019-12-21 20:55:43 +05:30
context "with #{statuses.join(",")}" do
it_behaves_like 'compares composite with SQL status' do
let(:all_statuses) do
statuses.map { |status| @statuses[status] }
end
let(:composite_status) do
described_class.new(all_statuses)
end
end
2020-07-28 23:09:34 +05:30
Ci::HasStatus::STATUSES_ENUM.each do |allow_failure_status, _|
2019-12-21 20:55:43 +05:30
context "and allow_failure #{allow_failure_status}" do
it_behaves_like 'compares composite with SQL status' do
let(:all_statuses) do
statuses.map { |status| @statuses[status] } +
[@statuses_with_allow_failure[allow_failure_status]]
end
let(:composite_status) do
described_class.new(all_statuses)
end
end
end
end
end
end
end
it_behaves_like 'validate all combinations', 0
it_behaves_like 'validate all combinations', 1
it_behaves_like 'validate all combinations', 2
end
end