diff options
| author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-15 16:29:29 +0200 |
|---|---|---|
| committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-15 18:32:08 +0200 |
| commit | 9dc6f9ad1e23df971f6cf3e412e47e3c5db1caab (patch) | |
| tree | 4d7c6009e2fa493b2001af6a17b2b6de5c4a47b0 /spec/lib | |
| parent | b8d919323c3ff84308706b2e488c13d9e38f96f4 (diff) | |
| download | gitlab-ce-ruby-composite-status.tar.gz | |
Test composite statusesruby-composite-status
Diffstat (limited to 'spec/lib')
| -rw-r--r-- | spec/lib/gitlab/ci/status/composite_status_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/status/composite_status_spec.rb b/spec/lib/gitlab/ci/status/composite_status_spec.rb new file mode 100644 index 00000000000..799bef666c3 --- /dev/null +++ b/spec/lib/gitlab/ci/status/composite_status_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Gitlab::Ci::Status::CompositeStatus do + set(:pipeline) { create(:ci_pipeline) } + + let(:composite_status) { described_class.new(all_statuses) } + + 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 + subject { composite_status.status.to_s } + + shared_examples 'compares composite with SQL status' do + it 'returns exactly the same result' do + is_expected.to eq(Ci::Build.where(id: all_statuses).legacy_status.to_s) + 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 + 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 + 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 + #it_behaves_like 'validate all combinations', 3 + end +end |
