Skip to content

Commit fd66693

Browse files
authored
Merge pull request kubernetes#128701 from pohly/prune-junit-xml-trailing-semicolon
prune-junit-xml: avoid appending semicolon
2 parents 31970d4 + dd6ad66 commit fd66693

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

cmd/prune-junit-xml/prunexml.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
139139
// The top level testcase element in a JUnit xml file does not have the / character.
140140
if testcase.Failure != nil {
141141
failflag = true
142-
updatedTestcaseFailure.Message = updatedTestcaseFailure.Message + testcase.Failure.Message + ";"
143-
updatedTestcaseFailure.Contents = updatedTestcaseFailure.Contents + testcase.Failure.Contents + ";"
144-
updatedTestcaseFailure.Type = updatedTestcaseFailure.Type + testcase.Failure.Type
142+
updatedTestcaseFailure.Message = joinTexts(updatedTestcaseFailure.Message, testcase.Failure.Message)
143+
updatedTestcaseFailure.Contents = joinTexts(updatedTestcaseFailure.Contents, testcase.Failure.Contents)
144+
updatedTestcaseFailure.Type = joinTexts(updatedTestcaseFailure.Type, testcase.Failure.Type)
145145
}
146146
}
147147
if failflag {
@@ -153,6 +153,18 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
153153
suites.Suites = updatedTestsuites
154154
}
155155

156+
// joinTexts returns "<a>; <b>" if both are non-empty,
157+
// otherwise just the non-empty string, if there is one.
158+
func joinTexts(a, b string) string {
159+
if a == "" {
160+
return b
161+
}
162+
if b == "" {
163+
return a
164+
}
165+
return a + "; " + b
166+
}
167+
156168
func fetchXML(xmlReader io.Reader) (*junitxml.JUnitTestSuites, error) {
157169
decoder := xml.NewDecoder(xmlReader)
158170
var suites junitxml.JUnitTestSuites

cmd/prune-junit-xml/prunexml_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ func TestPruneTESTS(t *testing.T) {
9696
<failure message="Failed" type="">FailureContent</failure>
9797
</testcase>
9898
</testsuite>
99+
<testsuite tests="3" failures="2" time="30.050000" name="k8s.io/kubernetes/test/integration/apimachinery2" timestamp="">
100+
<properties>
101+
<property name="go.version" value="go1.18 linux/amd64"></property>
102+
</properties>
103+
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watches" time="30.050000"></testcase>
104+
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestSchedulerInformers" time="-0.000000">
105+
<failure message="FailedA" type="">FailureContentA</failure>
106+
</testcase>
107+
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestSchedulerInformers2" time="-0.000000">
108+
<failure message="FailedB" type="">FailureContentB</failure>
109+
</testcase>
110+
</testsuite>
99111
</testsuites>`
100112

101113
outputXML := `<?xml version="1.0" encoding="UTF-8"?>
@@ -111,7 +123,15 @@ func TestPruneTESTS(t *testing.T) {
111123
<property name="go.version" value="go1.18 linux/amd64"></property>
112124
</properties>
113125
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery" time="30.050000">
114-
<failure message="Failed;" type="">FailureContent;</failure>
126+
<failure message="Failed" type="">FailureContent</failure>
127+
</testcase>
128+
</testsuite>
129+
<testsuite tests="3" failures="2" time="30.050000" name="k8s.io/kubernetes/test/integration/apimachinery2" timestamp="">
130+
<properties>
131+
<property name="go.version" value="go1.18 linux/amd64"></property>
132+
</properties>
133+
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery2" time="30.050000">
134+
<failure message="FailedA; FailedB" type="">FailureContentA; FailureContentB</failure>
115135
</testcase>
116136
</testsuite>
117137
</testsuites>`

0 commit comments

Comments
 (0)