summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/reports/test_suite_summary.rb
blob: 461aefc6fa916d402ac40f2d7ec8c5d69f462cb5 (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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Reports
      class TestSuiteSummary
        include Gitlab::Utils::StrongMemoize

        def initialize(build_report_results)
          @build_report_results = build_report_results
        end

        def name
          @name ||= @build_report_results.first.tests_name
        end

        # rubocop: disable CodeReuse/ActiveRecord
        def build_ids
          @build_report_results.pluck(:build_id)
        end

        def total_time
          @total_time ||= @build_report_results.sum(&:tests_duration)
        end

        def success_count
          @success_count ||= @build_report_results.sum(&:tests_success)
        end

        def failed_count
          @failed_count ||= @build_report_results.sum(&:tests_failed)
        end

        def skipped_count
          @skipped_count ||= @build_report_results.sum(&:tests_skipped)
        end

        def error_count
          @error_count ||= @build_report_results.sum(&:tests_errored)
        end

        def total_count
          @total_count ||= [success_count, failed_count, skipped_count, error_count].sum
        end
        # rubocop: disable CodeReuse/ActiveRecord

        def suite_error
          strong_memoize(:suite_error) do
            @build_report_results.map(&:suite_error).compact.first
          end
        end

        def to_h
          {
            time: total_time,
            count: total_count,
            success: success_count,
            failed: failed_count,
            skipped: skipped_count,
            error: error_count,
            suite_error: suite_error
          }
        end
      end
    end
  end
end