Skip to content

Commit da5aae9

Browse files
committed
Add filtering for JUnit to correctly produce pdcsi_junit.xml file
1 parent 99542b0 commit da5aae9

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

Diff for: test/k8s-integration/filter-junit.go

+21-17
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import (
3434
*/
3535

3636
type TestSuites struct {
37-
XMLName string `xml:"testsuites"`
38-
TestSuite []TestSuite `xml:"testsuite"`
37+
XMLName string `xml:"testsuites"`
38+
TestSuites []TestSuite `xml:"testsuite"`
3939
}
4040
type TestSuite struct {
41+
XMLName string `xml:"testsuite"`
4142
TestCases []TestCase `xml:"testcase"`
4243
}
4344

@@ -71,13 +72,16 @@ func (s SkipReason) MarshalText() ([]byte, error) {
7172
// MergeJUnit merges all junit xml files found in sourceDirectories into a single xml file at destination, using the filter.
7273
// The merging removes duplicate skipped tests. The original files are deleted.
7374
func MergeJUnit(testFilter string, sourceDirectories []string, destination string) error {
74-
var junit TestSuite
75+
var outputTestSuite TestSuite
7576
var data []byte
7677

7778
re := regexp.MustCompile(testFilter)
7879

7980
var mergeErrors []string
8081
var filesToDelete []string
82+
var junit TestSuites
83+
// Keep only matching testcases. Testcases skipped in all test runs are only stored once.
84+
filtered := map[string]TestCase{}
8185
for _, dir := range sourceDirectories {
8286
files, err := os.ReadDir(dir)
8387
if err != nil {
@@ -98,24 +102,24 @@ func MergeJUnit(testFilter string, sourceDirectories []string, destination strin
98102
if err = xml.Unmarshal(data, &junit); err != nil {
99103
return err
100104
}
101-
}
102-
}
103105

104-
// Keep only matching testcases. Testcases skipped in all test runs are only stored once.
105-
filtered := map[string]TestCase{}
106-
for _, testcase := range junit.TestCases {
107-
if !re.MatchString(testcase.Name) {
108-
continue
109-
}
110-
entry, ok := filtered[testcase.Name]
111-
if !ok || // not present yet
112-
entry.Skipped != "" && testcase.Skipped == "" { // replaced skipped test with real test run
113-
filtered[testcase.Name] = testcase
106+
for _, testsuite := range junit.TestSuites {
107+
for _, testcase := range testsuite.TestCases {
108+
if !re.MatchString(testcase.Name) {
109+
continue
110+
}
111+
entry, ok := filtered[testcase.Name]
112+
if !ok || // not present yet
113+
entry.Skipped != "" && testcase.Skipped == "" { // replaced skipped test with real test run
114+
filtered[testcase.Name] = testcase
115+
}
116+
}
117+
}
114118
}
115119
}
116-
junit.TestCases = nil
120+
outputTestSuite.TestCases = make([]TestCase, 0, len(filtered))
117121
for _, testcase := range filtered {
118-
junit.TestCases = append(junit.TestCases, testcase)
122+
outputTestSuite.TestCases = append(outputTestSuite.TestCases, testcase)
119123
}
120124

121125
// Re-encode.

0 commit comments

Comments
 (0)