From fcb64dfc0f4b1b6232872483df49f1d747316260 Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:47:35 +0300 Subject: [PATCH 01/14] fix: JUnit processing for large files --- .../artifacts/junit_post_processor.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go b/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go index d7cdc837d8a..da00ea57740 100644 --- a/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go +++ b/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go @@ -106,10 +106,16 @@ func isXMLFile(stat fs.FileInfo) bool { // isJUnitReport checks if the file starts with a JUnit XML tag func isJUnitReport(xmlData []byte) (bool, error) { + const BYTE_SIZE_8KB = 8 * 1024 + + // Limit check to first 8KB + if len(xmlData) > BYTE_SIZE_8KB { + xmlData = xmlData[:BYTE_SIZE_8KB] + } + scanner := bufio.NewScanner(bytes.NewReader(xmlData)) - // Read only the first few lines of the file for scanner.Scan() { - line := scanner.Text() + line := strings.TrimSpace(scanner.Text()) line = strings.TrimSpace(line) // Remove leading and trailing whitespace // Skip comments and declarations From d304e01c352ac208a4e83cd7360a241f5cf9148d Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:09:04 +0300 Subject: [PATCH 02/14] fix: parsing one-line JUnit reports --- .../artifacts/junit_post_processor.go | 37 +++++++------------ .../artifacts/junit_post_processor_test.go | 10 +++-- .../common/testdata/junit.go | 2 + 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go b/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go index da00ea57740..f8b1294f996 100644 --- a/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go +++ b/cmd/testworkflow-toolkit/artifacts/junit_post_processor.go @@ -1,8 +1,6 @@ package artifacts import ( - "bufio" - "bytes" "context" "fmt" "io" @@ -63,10 +61,7 @@ func (p *JUnitPostProcessor) Add(path string) error { if err != nil { return errors.Wrapf(err, "failed to read %s", path) } - ok, err := isJUnitReport(xmlData) - if err != nil { - return errors.Wrapf(err, "failed to check if %s is a JUnit report", path) - } + ok := isJUnitReport(xmlData) if !ok { return nil } @@ -104,33 +99,29 @@ func isXMLFile(stat fs.FileInfo) bool { return strings.HasSuffix(stat.Name(), ".xml") } -// isJUnitReport checks if the file starts with a JUnit XML tag -func isJUnitReport(xmlData []byte) (bool, error) { +// isJUnitReport checks if the XML data is a JUnit report. +func isJUnitReport(xmlData []byte) bool { const BYTE_SIZE_8KB = 8 * 1024 - // Limit check to first 8KB + tags := []string{ + " BYTE_SIZE_8KB { xmlData = xmlData[:BYTE_SIZE_8KB] } - scanner := bufio.NewScanner(bytes.NewReader(xmlData)) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - line = strings.TrimSpace(line) // Remove leading and trailing whitespace + content := string(xmlData) - // Skip comments and declarations - if strings.HasPrefix(line, "