2020-06-02 17:08:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class BuildReportResultService
|
2020-10-05 08:08:47 -04:00
|
|
|
include Gitlab::Utils::UsageData
|
|
|
|
|
|
|
|
EVENT_NAME = 'i_testing_test_case_parsed'
|
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
def execute(build)
|
|
|
|
return unless build.has_test_reports?
|
|
|
|
|
2020-10-05 08:08:47 -04:00
|
|
|
test_suite = generate_test_suite_report(build)
|
|
|
|
|
|
|
|
track_test_cases(build, test_suite)
|
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
build.report_results.create!(
|
|
|
|
project_id: build.project_id,
|
2020-10-05 08:08:47 -04:00
|
|
|
data: tests_params(test_suite)
|
2020-06-02 17:08:00 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def generate_test_suite_report(build)
|
|
|
|
build.collect_test_reports!(Gitlab::Ci::Reports::TestReports.new)
|
|
|
|
end
|
|
|
|
|
2020-10-05 08:08:47 -04:00
|
|
|
def tests_params(test_suite)
|
2020-06-02 17:08:00 -04:00
|
|
|
{
|
|
|
|
tests: {
|
|
|
|
name: test_suite.name,
|
|
|
|
duration: test_suite.total_time,
|
|
|
|
failed: test_suite.failed_count,
|
|
|
|
errored: test_suite.error_count,
|
|
|
|
skipped: test_suite.skipped_count,
|
2021-03-12 16:09:12 -05:00
|
|
|
success: test_suite.success_count,
|
|
|
|
suite_error: test_suite.suite_error
|
2020-06-02 17:08:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2020-10-05 08:08:47 -04:00
|
|
|
|
|
|
|
def track_test_cases(build, test_suite)
|
|
|
|
track_usage_event(EVENT_NAME, test_case_hashes(build, test_suite))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_case_hashes(build, test_suite)
|
|
|
|
[].tap do |hashes|
|
|
|
|
test_suite.each_test_case do |test_case|
|
2020-10-08 02:08:35 -04:00
|
|
|
key = "#{build.project_id}-#{test_case.key}"
|
2020-10-05 08:08:47 -04:00
|
|
|
hashes << Digest::SHA256.hexdigest(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-02 17:08:00 -04:00
|
|
|
end
|
|
|
|
end
|