prune-junit-xml: preserve system out + err text during test pruning

When stripping out log messages from the failure text, the original text gets
stored as <system-out>. That part then got lost when reducing tests. Instead of
dropping it, it needs to be joined from all failed tests. Same for
<system-err>, although that isn't used yet.
This commit is contained in:
Patrick Ohly 2024-12-02 10:24:13 +01:00
parent e0e4af8a58
commit b330eeac2f
2 changed files with 16 additions and 1 deletions

View File

@ -135,6 +135,8 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
updatedTestcase.Classname = match[1]
updatedTestcase.Name = match[2]
updatedTestcase.Time = suite.Time
updatedSystemOut := ""
updatedSystemErr := ""
for _, testcase := range suite.TestCases {
// The top level testcase element in a JUnit xml file does not have the / character.
if testcase.Failure != nil {
@ -142,10 +144,14 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) {
updatedTestcaseFailure.Message = joinTexts(updatedTestcaseFailure.Message, testcase.Failure.Message)
updatedTestcaseFailure.Contents = joinTexts(updatedTestcaseFailure.Contents, testcase.Failure.Contents)
updatedTestcaseFailure.Type = joinTexts(updatedTestcaseFailure.Type, testcase.Failure.Type)
updatedSystemOut = joinTexts(updatedSystemOut, testcase.SystemOut)
updatedSystemErr = joinTexts(updatedSystemErr, testcase.SystemErr)
}
}
if failflag {
updatedTestcase.Failure = &updatedTestcaseFailure
updatedTestcase.SystemOut = updatedSystemOut
updatedTestcase.SystemErr = updatedSystemErr
}
suite.TestCases = append(updatedTestcases, updatedTestcase)
updatedTestsuites = append(updatedTestsuites, suite)

View File

@ -100,7 +100,10 @@ func TestPruneTESTS(t *testing.T) {
<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="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">
<failure message="FailedA" type="">FailureContentA</failure>
</testcase>
@ -114,9 +117,13 @@ func TestPruneTESTS(t *testing.T) {
</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&#xA;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>
@ -154,6 +161,8 @@ func TestPruneTESTS(t *testing.T) {
</properties>
<testcase classname="k8s.io/kubernetes/test/integration" name="apimachinery3" time="40.050000">
<failure message="Failed" type="">RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA&#xA;expected foo, got bar&#xA;&#xA;sub-test failed</failure>
<system-out>out A&#xA;&#xA;out B</system-out>
<system-err>err A&#xA;&#xA;err B</system-err>
</testcase>
</testsuite>
</testsuites>`