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
17
# File 'lib/gitlab/ci/reports/test_suite.rb', line 12

def initialize(name = nil)
  @name = name
  @test_cases = {}
  @all_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


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

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


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

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


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

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


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

def set_suite_error(msg)
  @suite_error = msg
end

#sortedObject


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

def sorted
  sort_by_status
  sort_by_execution_time_desc
  self
end

#total_countObject

rubocop: disable CodeReuse/ActiveRecord


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

def total_count
  return 0 if suite_error

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

#total_statusObject

rubocop: enable CodeReuse/ActiveRecord


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

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


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

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