Class: Gitlab::Ci::Reports::TestSuiteComparer

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/reports/test_suite_comparer.rb

Defined Under Namespace

Classes: TestSummary

Constant Summary collapse

DEFAULT_MAX_TESTS =
100
DEFAULT_MIN_TESTS =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, base_suite, head_suite) ⇒ TestSuiteComparer

Returns a new instance of TestSuiteComparer.



15
16
17
18
19
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 15

def initialize(name, base_suite, head_suite)
  @name = name
  @base_suite = base_suite || TestSuite.new
  @head_suite = head_suite
end

Instance Attribute Details

#base_suiteObject (readonly)

Returns the value of attribute base_suite.



13
14
15
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 13

def base_suite
  @base_suite
end

#head_suiteObject (readonly)

Returns the value of attribute head_suite.



13
14
15
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 13

def head_suite
  @head_suite
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 13

def name
  @name
end

Instance Method Details

#error_countObject



85
86
87
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 85

def error_count
  new_errors.count + existing_errors.count
end

#existing_errorsObject



53
54
55
56
57
58
59
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 53

def existing_errors
  strong_memoize(:existing_errors) do
    head_suite.error.select do |key, _|
      base_suite.error.include?(key)
    end.values
  end
end

#existing_failuresObject



29
30
31
32
33
34
35
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 29

def existing_failures
  strong_memoize(:existing_failures) do
    head_suite.failed.select do |key, _|
      base_suite.failed.include?(key)
    end.values
  end
end

#failed_countObject



81
82
83
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 81

def failed_count
  new_failures.count + existing_failures.count
end

#limited_testsObject

This is used to limit the presented test cases but does not affect total count of tests in the summary



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 91

def limited_tests
  strong_memoize(:limited_tests) do
    # rubocop: disable CodeReuse/ActiveRecord
    TestSummary.new(
      new_failures: new_failures.take(max_tests),
      existing_failures: existing_failures.take(max_tests(new_failures)),
      resolved_failures: resolved_failures.take(max_tests(new_failures, existing_failures)),
      new_errors: new_errors.take(max_tests),
      existing_errors: existing_errors.take(max_tests(new_errors)),
      resolved_errors: resolved_errors.take(max_tests(new_errors, existing_errors))
    )
    # rubocop: enable CodeReuse/ActiveRecord
  end
end

#new_errorsObject



45
46
47
48
49
50
51
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 45

def new_errors
  strong_memoize(:new_errors) do
    head_suite.error.reject do |key, _|
      base_suite.error.include?(key)
    end.values
  end
end

#new_failuresObject



21
22
23
24
25
26
27
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 21

def new_failures
  strong_memoize(:new_failures) do
    head_suite.failed.reject do |key, _|
      base_suite.failed.include?(key)
    end.values
  end
end

#resolved_countObject



77
78
79
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 77

def resolved_count
  resolved_failures.count + resolved_errors.count
end

#resolved_errorsObject



61
62
63
64
65
66
67
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 61

def resolved_errors
  strong_memoize(:resolved_errors) do
    head_suite.success.select do |key, _|
      base_suite.error.include?(key)
    end.values
  end
end

#resolved_failuresObject



37
38
39
40
41
42
43
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 37

def resolved_failures
  strong_memoize(:resolved_failures) do
    head_suite.success.select do |key, _|
      base_suite.failed.include?(key)
    end.values
  end
end

#total_countObject



69
70
71
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 69

def total_count
  head_suite.total_count
end

#total_statusObject



73
74
75
# File 'lib/gitlab/ci/reports/test_suite_comparer.rb', line 73

def total_status
  head_suite.total_status
end