summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/status/composite_spec.rb
blob: e1dcd05373f4037b0061789e13c8d3195b315347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Status::Composite do
  let_it_be(:pipeline) { create(:ci_pipeline) }

  before_all do
    @statuses = Ci::HasStatus::STATUSES_ENUM.map do |status, idx|
      [status, create(:ci_build, pipeline: pipeline, status: status, importing: true)]
    end.to_h

    @statuses_with_allow_failure = Ci::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
    using RSpec::Parameterized::TableSyntax

    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)
      end
    end

    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] }
        end

        it_behaves_like 'compares status and warnings'
      end
    end

    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
  end
end