blob: 741c62707b01d814650340ca111c44b849c660c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
module Gitlab
module Ci
module Parsers
class JunitParser
attr_reader :data
JunitParserError = Class.new(StandardError)
def initialize(xml_data)
@data = Hash.from_xml(xml_data)
rescue
raise JunitParserError, 'Invalid XML data'
end
def parse!(test_suite)
each_suite do |testcases|
testcases.each do |testcase|
test_case = create_test_case(testcase)
test_suite.add_test_case(test_case)
end
end
rescue
raise JunitParserError, 'Invalid JUnit xml structure'
end
private
def each_suite
testsuites.each do |testsuite|
yield testcases(testsuite)
end
end
def testsuites
if data['testsuites']
data['testsuites']['testsuite']
else
[data['testsuite']]
end
end
def testcases(testsuite)
if testsuite['testcase'].is_a?(Array)
testsuite['testcase']
else
[testsuite['testcase']]
end
end
def create_test_case(data)
if data['failure']
status = ::Gitlab::Ci::Reports::TestCase::STATUS_FAILED
system_output = data['failure']
else
status = ::Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS
system_output = nil
end
::Gitlab::Ci::Reports::TestCase.new(
classname: data['classname'],
name: data['name'],
file: data['file'],
execution_time: data['time'],
status: status,
system_output: system_output
)
end
end
end
end
end
|