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

62 lines
1.6 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 TestReports
attr_reader :test_suites
def initialize
@test_suites = {}
end
def get_suite(suite_name)
test_suites[suite_name] ||= TestSuite.new(suite_name)
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
def total_time
test_suites.values.sum(&:total_time)
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
def total_count
test_suites.values.sum(&:total_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
if failed_count > 0 || error_count > 0
TestCase::STATUS_FAILED
else
TestCase::STATUS_SUCCESS
end
end
2020-04-22 19:07:51 +05:30
def with_attachment!
@test_suites.keep_if do |_job_name, test_suite|
test_suite.with_attachment!.present?
end
self
end
2020-05-24 23:13:21 +05:30
def suite_errors
test_suites.each_with_object({}) do |(name, suite), errors|
errors[suite.name] = suite.suite_error if suite.suite_error
end
end
2018-11-18 11:00:15 +05:30
TestCase::STATUS_TYPES.each do |status_type|
define_method("#{status_type}_count") do
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
test_suites.values.sum { |suite| suite.public_send("#{status_type}_count") } # rubocop:disable GitlabSecurity/PublicSend
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
end
end
end
end
end
end