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 = {}
  @total_time = 0.0
  @duplicate_cases = []
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


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

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

def add_test_case(test_case)
  @duplicate_cases << test_case if existing_key?(test_case)

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

#set_suite_error(msg) ⇒ Object


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

def set_suite_error(msg)
  @suite_error = msg
end

#sortedObject


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

def sorted
  sort_by_status
  sort_by_execution_time_desc
  self
end

#total_countObject

rubocop: disable CodeReuse/ActiveRecord


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

def total_count
  return 0 if suite_error

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

#total_statusObject

rubocop: enable CodeReuse/ActiveRecord


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

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


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

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