Class: Gitlab::Ci::Reports::TestSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/reports/test_suite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ TestSuite

Returns a new instance of TestSuite.


12
13
14
15
16
# File 'lib/gitlab/ci/reports/test_suite.rb', line 12

def initialize(name = nil)
  @name = name
  @test_cases = {}
  @total_time = 0.0
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.


7
8
9
# File 'lib/gitlab/ci/reports/test_suite.rb', line 7

def name
  @name
end

#suite_errorObject (readonly)

Returns the value of attribute suite_error.


10
11
12
# File 'lib/gitlab/ci/reports/test_suite.rb', line 10

def suite_error
  @suite_error
end

#test_casesObject

Returns the value of attribute test_cases.


8
9
10
# File 'lib/gitlab/ci/reports/test_suite.rb', line 8

def test_cases
  @test_cases
end

#total_timeObject

Returns the value of attribute total_time.


9
10
11
# File 'lib/gitlab/ci/reports/test_suite.rb', line 9

def total_time
  @total_time
end

Instance Method Details

#+(other) ⇒ Object


78
79
80
81
82
83
84
# File 'lib/gitlab/ci/reports/test_suite.rb', line 78

def +(other)
  self.class.new.tap do |test_suite|
    test_suite.name = self.name
    test_suite.test_cases = self.test_cases.deep_merge(other.test_cases)
    test_suite.total_time = self.total_time + other.total_time
  end
end

#add_test_case(test_case) ⇒ Object


18
19
20
21
22
# File 'lib/gitlab/ci/reports/test_suite.rb', line 18

def add_test_case(test_case)
  @test_cases[test_case.status] ||= {}
  @test_cases[test_case.status][test_case.key] = test_case
  @total_time += test_case.execution_time
end

#each_test_caseObject


24
25
26
27
28
29
30
# File 'lib/gitlab/ci/reports/test_suite.rb', line 24

def each_test_case
  @test_cases.each do |status, test_cases|
    test_cases.values.each do |test_case|
      yield test_case
    end
  end
end

#set_suite_error(msg) ⇒ Object


74
75
76
# File 'lib/gitlab/ci/reports/test_suite.rb', line 74

def set_suite_error(msg)
  @suite_error = msg
end

#sortedObject


86
87
88
89
90
# File 'lib/gitlab/ci/reports/test_suite.rb', line 86

def sorted
  sort_by_status
  sort_by_execution_time_desc
  self
end

#total_countObject

rubocop: disable CodeReuse/ActiveRecord


33
34
35
36
37
# File 'lib/gitlab/ci/reports/test_suite.rb', line 33

def total_count
  return 0 if suite_error

  [success_count, failed_count, skipped_count, error_count].sum
end

#total_statusObject

rubocop: enable CodeReuse/ActiveRecord


40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/ci/reports/test_suite.rb', line 40

def total_status
  if suite_error
    TestCase::STATUS_ERROR
  elsif failed_count > 0 || error_count > 0
    TestCase::STATUS_FAILED
  else
    TestCase::STATUS_SUCCESS
  end
end

#with_attachment!Object


50
51
52
53
54
55
56
57
58
# File 'lib/gitlab/ci/reports/test_suite.rb', line 50

def with_attachment!
  @test_cases = @test_cases.extract!("failed")

  @test_cases.keep_if do |status, hash|
    hash.any? do |key, test_case|
      test_case.has_attachment?
    end
  end
end