debian-mirror-gitlab/lib/gitlab/ci/reports/test_suite.rb

90 lines
2.3 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-11-18 11:00:15 +05:30
module Gitlab
module Ci
module Reports
class TestSuite
2020-07-28 23:09:34 +05:30
attr_accessor :name
attr_accessor :test_cases
attr_accessor :total_time
2020-05-24 23:13:21 +05:30
attr_reader :suite_error
2018-11-18 11:00:15 +05:30
def initialize(name = nil)
@name = name
@test_cases = {}
@total_time = 0.0
@duplicate_cases = []
end
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
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
def total_count
2020-05-24 23:13:21 +05:30
return 0 if suite_error
2018-11-18 11:00:15 +05:30
test_cases.values.sum(&:count)
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
def total_status
2020-05-24 23:13:21 +05:30
if suite_error
TestCase::STATUS_ERROR
elsif failed_count > 0 || error_count > 0
2018-11-18 11:00:15 +05:30
TestCase::STATUS_FAILED
else
TestCase::STATUS_SUCCESS
end
end
2020-04-22 19:07:51 +05:30
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
2018-11-18 11:00:15 +05:30
TestCase::STATUS_TYPES.each do |status_type|
define_method("#{status_type}") do
2020-05-24 23:13:21 +05:30
return {} if suite_error || test_cases[status_type].nil?
test_cases[status_type]
2018-11-18 11:00:15 +05:30
end
define_method("#{status_type}_count") do
2020-05-24 23:13:21 +05:30
return 0 if suite_error || test_cases[status_type].nil?
test_cases[status_type].length
2018-11-18 11:00:15 +05:30
end
end
2020-05-24 23:13:21 +05:30
def set_suite_error(msg)
@suite_error = msg
end
2020-07-28 23:09:34 +05:30
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
2018-11-18 11:00:15 +05:30
private
def existing_key?(test_case)
@test_cases[test_case.status]&.key?(test_case.key)
end
end
end
end
end