diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 15:05:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 15:05:59 +0300 |
commit | 9e27f0d920cc3891fa7644c5cc0bc280c519fb20 (patch) | |
tree | 9784dd99270f2009159b19077412bf83d13123a4 /spec/lib/gitlab/ci/status | |
parent | 1bab0ba591263cd739af2d2c7c3f1b03678a59b6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/ci/status')
-rw-r--r-- | spec/lib/gitlab/ci/status/composite_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/status/composite_spec.rb b/spec/lib/gitlab/ci/status/composite_spec.rb new file mode 100644 index 00000000000..1725d954b92 --- /dev/null +++ b/spec/lib/gitlab/ci/status/composite_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Gitlab::Ci::Status::Composite do + set(:pipeline) { create(:ci_pipeline) } + + before(:all) do + @statuses = HasStatus::STATUSES_ENUM.map do |status, idx| + [status, create(:ci_build, pipeline: pipeline, status: status, importing: true)] + end.to_h + + @statuses_with_allow_failure = HasStatus::STATUSES_ENUM.map do |status, idx| + [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| + HasStatus::STATUSES_ENUM.keys.combination(perms).each do |statuses| + 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 + + HasStatus::STATUSES_ENUM.each do |allow_failure_status, _| + 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 |