@@ -42,13 +42,14 @@ func TestJunitXML_Print(t *testing.T) {
4242 },
4343 }
4444
45- buf := new (bytes.Buffer )
46- printer := NewJunitXML (buf )
47-
48- err := printer .Print (issues )
49- require .NoError (t , err )
50-
51- expected := `<testsuites>
45+ testCases := []struct {
46+ desc string
47+ extended bool
48+ expected string
49+ }{
50+ {
51+ desc : "basic" ,
52+ expected : `<testsuites>
5253 <testsuite name="path/to/filea.go" tests="1" errors="0" failures="1">
5354 <testcase name="linter-a" classname="path/to/filea.go:10:4">
5455 <failure message="path/to/filea.go:10:4: some issue" type="warning"><![CDATA[warning: some issue
@@ -69,7 +70,47 @@ Details: func foo() {
6970}]]></failure>
7071 </testcase>
7172 </testsuite>
72- </testsuites>`
73+ </testsuites>` ,
74+ },
75+ {
76+ desc : "extended/complete" ,
77+ extended : true ,
78+ expected : `<testsuites>
79+ <testsuite name="path/to/filea.go" tests="1" errors="0" failures="1">
80+ <testcase name="linter-a" classname="path/to/filea.go:10:4" file="path/to/filea.go" line="10">
81+ <failure message="path/to/filea.go:10:4: some issue" type="warning"><![CDATA[warning: some issue
82+ Category: linter-a
83+ File: path/to/filea.go
84+ Line: 10
85+ Details: ]]></failure>
86+ </testcase>
87+ </testsuite>
88+ <testsuite name="path/to/fileb.go" tests="1" errors="0" failures="1">
89+ <testcase name="linter-b" classname="path/to/fileb.go:300:9" file="path/to/fileb.go" line="300">
90+ <failure message="path/to/fileb.go:300:9: another issue" type="error"><![CDATA[error: another issue
91+ Category: linter-b
92+ File: path/to/fileb.go
93+ Line: 300
94+ Details: func foo() {
95+ fmt.Println("bar")
96+ }]]></failure>
97+ </testcase>
98+ </testsuite>
99+ </testsuites>` ,
100+ },
101+ }
102+
103+ for _ , test := range testCases {
104+ t .Run (test .desc , func (t * testing.T ) {
105+ t .Parallel ()
73106
74- assert .Equal (t , expected , buf .String ())
107+ buf := new (bytes.Buffer )
108+ printer := NewJunitXML (test .extended , buf )
109+
110+ err := printer .Print (issues )
111+ require .NoError (t , err )
112+
113+ assert .Equal (t , test .expected , buf .String ())
114+ })
115+ }
75116}
0 commit comments