mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Merge pull request #129035 from pohly/prune-junit-xml-failure-fix
prune-junit-xml: join stdout when merging tests
This commit is contained in:
commit
3e4e1364db
@ -135,6 +135,8 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
|
|||||||
updatedTestcase.Classname = match[1]
|
updatedTestcase.Classname = match[1]
|
||||||
updatedTestcase.Name = match[2]
|
updatedTestcase.Name = match[2]
|
||||||
updatedTestcase.Time = suite.Time
|
updatedTestcase.Time = suite.Time
|
||||||
|
updatedSystemOut := ""
|
||||||
|
updatedSystemErr := ""
|
||||||
for _, testcase := range suite.TestCases {
|
for _, testcase := range suite.TestCases {
|
||||||
// The top level testcase element in a JUnit xml file does not have the / character.
|
// The top level testcase element in a JUnit xml file does not have the / character.
|
||||||
if testcase.Failure != nil {
|
if testcase.Failure != nil {
|
||||||
@ -142,10 +144,14 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
|
|||||||
updatedTestcaseFailure.Message = joinTexts(updatedTestcaseFailure.Message, testcase.Failure.Message)
|
updatedTestcaseFailure.Message = joinTexts(updatedTestcaseFailure.Message, testcase.Failure.Message)
|
||||||
updatedTestcaseFailure.Contents = joinTexts(updatedTestcaseFailure.Contents, testcase.Failure.Contents)
|
updatedTestcaseFailure.Contents = joinTexts(updatedTestcaseFailure.Contents, testcase.Failure.Contents)
|
||||||
updatedTestcaseFailure.Type = joinTexts(updatedTestcaseFailure.Type, testcase.Failure.Type)
|
updatedTestcaseFailure.Type = joinTexts(updatedTestcaseFailure.Type, testcase.Failure.Type)
|
||||||
|
updatedSystemOut = joinTexts(updatedSystemOut, testcase.SystemOut)
|
||||||
|
updatedSystemErr = joinTexts(updatedSystemErr, testcase.SystemErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if failflag {
|
if failflag {
|
||||||
updatedTestcase.Failure = &updatedTestcaseFailure
|
updatedTestcase.Failure = &updatedTestcaseFailure
|
||||||
|
updatedTestcase.SystemOut = updatedSystemOut
|
||||||
|
updatedTestcase.SystemErr = updatedSystemErr
|
||||||
}
|
}
|
||||||
suite.TestCases = append(updatedTestcases, updatedTestcase)
|
suite.TestCases = append(updatedTestcases, updatedTestcase)
|
||||||
updatedTestsuites = append(updatedTestsuites, suite)
|
updatedTestsuites = append(updatedTestsuites, suite)
|
||||||
@ -153,8 +159,15 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
|
|||||||
suites.Suites = updatedTestsuites
|
suites.Suites = updatedTestsuites
|
||||||
}
|
}
|
||||||
|
|
||||||
// joinTexts returns "<a>; <b>" if both are non-empty,
|
// joinTexts returns "<a><empty line><b>" if both are non-empty,
|
||||||
// otherwise just the non-empty string, if there is one.
|
// otherwise just the non-empty string, if there is one.
|
||||||
|
//
|
||||||
|
// If <b> is contained completely in <a>, <a> gets returned because repeating
|
||||||
|
// exactly the same string again doesn't add any information. Typically
|
||||||
|
// this occurs when joining the failure message because that is the fixed
|
||||||
|
// string "Failed" for all tests, regardless of what the test logged.
|
||||||
|
// The test log output is typically different because it cointains "=== RUN
|
||||||
|
// <test name>" and thus doesn't get dropped.
|
||||||
func joinTexts(a, b string) string {
|
func joinTexts(a, b string) string {
|
||||||
if a == "" {
|
if a == "" {
|
||||||
return b
|
return b
|
||||||
@ -162,7 +175,14 @@ func joinTexts(a, b string) string {
|
|||||||
if b == "" {
|
if b == "" {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
return a + "; " + b
|
if strings.Contains(a, b) {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
sep := "\n"
|
||||||
|
if !strings.HasSuffix(a, "\n") {
|
||||||
|
sep = "\n\n"
|
||||||
|
}
|
||||||
|
return a + sep + b
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchXML(xmlReader io.Reader) (*junitxml.JUnitTestSuites, error) {
|
func fetchXML(xmlReader io.Reader) (*junitxml.JUnitTestSuites, error) {
|
||||||
|
@ -100,7 +100,10 @@ func TestPruneTESTS(t *testing.T) {
|
|||||||
<properties>
|
<properties>
|
||||||
<property name="go.version" value="go1.18 linux/amd64"></property>
|
<property name="go.version" value="go1.18 linux/amd64"></property>
|
||||||
</properties>
|
</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="TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watches" time="30.050000">
|
||||||
|
<system-out>out A</system-out>
|
||||||
|
<system-err>err B</system-err>
|
||||||
|
</testcase>
|
||||||
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestSchedulerInformers" time="-0.000000">
|
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery2" name="TestSchedulerInformers" time="-0.000000">
|
||||||
<failure message="FailedA" type="">FailureContentA</failure>
|
<failure message="FailedA" type="">FailureContentA</failure>
|
||||||
</testcase>
|
</testcase>
|
||||||
@ -108,6 +111,24 @@ func TestPruneTESTS(t *testing.T) {
|
|||||||
<failure message="FailedB" type="">FailureContentB</failure>
|
<failure message="FailedB" type="">FailureContentB</failure>
|
||||||
</testcase>
|
</testcase>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
<testsuite tests="3" failures="3" time="40.050000" name="k8s.io/kubernetes/test/integration/apimachinery3" timestamp="">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="go1.18 linux/amd64"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery3" name="TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watches" time="40.050000">
|
||||||
|
<failure message="Failed" type="">RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA
expected foo, got bar</failure>
|
||||||
|
<system-out>out A</system-out>
|
||||||
|
<system-err>err A</system-err>
|
||||||
|
</testcase>
|
||||||
|
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery3" name="TestWatchRestartsIfTimeoutNotReached/group" time="40.050000">
|
||||||
|
<failure message="Failed" type="">sub-test failed</failure>
|
||||||
|
<system-out>out B</system-out>
|
||||||
|
<system-err>err B</system-err>
|
||||||
|
</testcase>
|
||||||
|
<testcase classname="k8s.io/kubernetes/test/integration/apimachinery3" name="TestWatchRestartsIfTimeoutNotReached" time="40.050000">
|
||||||
|
<failure message="Failed" type="">sub-test failed</failure>
|
||||||
|
</testcase>
|
||||||
|
</testsuite>
|
||||||
</testsuites>`
|
</testsuites>`
|
||||||
|
|
||||||
outputXML := `<?xml version="1.0" encoding="UTF-8"?>
|
outputXML := `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@ -131,7 +152,17 @@ func TestPruneTESTS(t *testing.T) {
|
|||||||
<property name="go.version" value="go1.18 linux/amd64"></property>
|
<property name="go.version" value="go1.18 linux/amd64"></property>
|
||||||
</properties>
|
</properties>
|
||||||
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery2" time="30.050000">
|
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery2" time="30.050000">
|
||||||
<failure message="FailedA; FailedB" type="">FailureContentA; FailureContentB</failure>
|
<failure message="FailedA

FailedB" type="">FailureContentA

FailureContentB</failure>
|
||||||
|
</testcase>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite tests="3" failures="3" time="40.050000" name="k8s.io/kubernetes/test/integration/apimachinery3" timestamp="">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="go1.18 linux/amd64"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery3" time="40.050000">
|
||||||
|
<failure message="Failed" type="">RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA
expected foo, got bar

sub-test failed</failure>
|
||||||
|
<system-out>out A

out B</system-out>
|
||||||
|
<system-err>err A

err B</system-err>
|
||||||
</testcase>
|
</testcase>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>`
|
</testsuites>`
|
||||||
|
Loading…
Reference in New Issue
Block a user