Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering for JUnit to correctly produce pdcsi_junit.xml file #1913

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions test/k8s-integration/filter-junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import (
*/

type TestSuites struct {
XMLName string `xml:"testsuites"`
TestSuite []TestSuite `xml:"testsuite"`
XMLName string `xml:"testsuites"`
TestSuites []TestSuite `xml:"testsuite"`
}
type TestSuite struct {
XMLName string `xml:"testsuite"`
TestCases []TestCase `xml:"testcase"`
}

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

re := regexp.MustCompile(testFilter)

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

// Keep only matching testcases. Testcases skipped in all test runs are only stored once.
filtered := map[string]TestCase{}
for _, testcase := range junit.TestCases {
if !re.MatchString(testcase.Name) {
continue
}
entry, ok := filtered[testcase.Name]
if !ok || // not present yet
entry.Skipped != "" && testcase.Skipped == "" { // replaced skipped test with real test run
filtered[testcase.Name] = testcase
for _, testsuite := range junit.TestSuites {
for _, testcase := range testsuite.TestCases {
if !re.MatchString(testcase.Name) {
continue
}
entry, ok := filtered[testcase.Name]
if !ok || // not present yet
entry.Skipped != "" && testcase.Skipped == "" { // replaced skipped test with real test run
filtered[testcase.Name] = testcase
}
}
}
}
}
junit.TestCases = nil
outputTestSuite.TestCases = make([]TestCase, 0, len(filtered))
for _, testcase := range filtered {
junit.TestCases = append(junit.TestCases, testcase)
outputTestSuite.TestCases = append(outputTestSuite.TestCases, testcase)
}

// Re-encode.
Expand Down