Merge pull request #128701 from pohly/prune-junit-xml-trailing-semicolon

prune-junit-xml: avoid appending semicolon
This commit is contained in:
Kubernetes Prow Robot 2024-11-08 17:54:50 +00:00 committed by GitHub
commit fd66693104
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 4 deletions

View File

@ -139,9 +139,9 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
// The top level testcase element in a JUnit xml file does not have the / character.
if testcase.Failure != nil {
failflag = true
updatedTestcaseFailure.Message = updatedTestcaseFailure.Message + testcase.Failure.Message + ";"
updatedTestcaseFailure.Contents = updatedTestcaseFailure.Contents + testcase.Failure.Contents + ";"
updatedTestcaseFailure.Type = updatedTestcaseFailure.Type + testcase.Failure.Type
updatedTestcaseFailure.Message = joinTexts(updatedTestcaseFailure.Message, testcase.Failure.Message)
updatedTestcaseFailure.Contents = joinTexts(updatedTestcaseFailure.Contents, testcase.Failure.Contents)
updatedTestcaseFailure.Type = joinTexts(updatedTestcaseFailure.Type, testcase.Failure.Type)
}
}
if failflag {
@ -153,6 +153,18 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
suites.Suites = updatedTestsuites
}
// joinTexts returns "<a>; <b>" if both are non-empty,
// otherwise just the non-empty string, if there is one.
func joinTexts(a, b string) string {
if a == "" {
return b
}
if b == "" {
return a
}
return a + "; " + b
}
func fetchXML(xmlReader io.Reader) (*junitxml.JUnitTestSuites, error) {
decoder := xml.NewDecoder(xmlReader)
var suites junitxml.JUnitTestSuites

View File

@ -96,6 +96,18 @@ func TestPruneTESTS(t *testing.T) {
<failure message="Failed" type="">FailureContent</failure>
</testcase>
</testsuite>
<testsuite tests="3" failures="2" time="30.050000" name="k8s.io/kubernetes/test/integration/apimachinery2" timestamp="">
<properties>
<property name="go.version" value="go1.18 linux/amd64"></property>
</properties>
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watches" time="30.050000"></testcase>
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestSchedulerInformers" time="-0.000000">
<failure message="FailedA" type="">FailureContentA</failure>
</testcase>
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestSchedulerInformers2" time="-0.000000">
<failure message="FailedB" type="">FailureContentB</failure>
</testcase>
</testsuite>
</testsuites>`
outputXML := `<?xml version="1.0" encoding="UTF-8"?>
@ -111,7 +123,15 @@ func TestPruneTESTS(t *testing.T) {
<property name="go.version" value="go1.18 linux/amd64"></property>
</properties>
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery" time="30.050000">
<failure message="Failed;" type="">FailureContent;</failure>
<failure message="Failed" type="">FailureContent</failure>
</testcase>
</testsuite>
<testsuite tests="3" failures="2" time="30.050000" name="k8s.io/kubernetes/test/integration/apimachinery2" timestamp="">
<properties>
<property name="go.version" value="go1.18 linux/amd64"></property>
</properties>
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery2" time="30.050000">
<failure message="FailedA; FailedB" type="">FailureContentA; FailureContentB</failure>
</testcase>
</testsuite>
</testsuites>`