Skip to content

Commit

Permalink
fix: send full junit report to cloud (#5898)
Browse files Browse the repository at this point in the history
* fix: send full junit report to cloud

* fix: use buffer

* fix: simplify logic
  • Loading branch information
devcatalin authored Oct 3, 2024
1 parent bdd483a commit 4aba7f8
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions cmd/testworkflow-toolkit/artifacts/junit_post_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,35 @@ func (p *JUnitPostProcessor) Add(path string) error {
return errors.Wrapf(err, "failed to open %s", path)
}
defer func() { _ = file.Close() }()

stat, err := file.Stat()
if err != nil {
return errors.Wrapf(err, "failed to get file info for %s", path)
}
if ok := isXMLFile(stat); !ok {
return nil
}
// Read only the first 8KB of data

// Read first 8KB
const BYTE_SIZE_8KB = 8 * 1024
xmlData := make([]byte, BYTE_SIZE_8KB)
n, err := file.Read(xmlData)
if err != nil && err != io.EOF {
return errors.Wrapf(err, "failed to read %s", path)
buffer := make([]byte, BYTE_SIZE_8KB)
n, err := io.ReadFull(file, buffer)
if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) && !errors.Is(err, io.EOF) {
return errors.Wrapf(err, "failed to read initial content from %s", path)
}
// Trim the slice to the actual number of bytes read
xmlData = xmlData[:n]
ok := isJUnitReport(xmlData)
if !ok {
buffer = buffer[:n] // Trim buffer to actual bytes read

if !isJUnitReport(buffer) {
return nil
}

// Read the rest of the file
rest, err := io.ReadAll(file)
if err != nil {
return errors.Wrapf(err, "failed to read remaining content from %s", path)
}
xmlData := append(buffer, rest...)

fmt.Printf("Processing JUnit report: %s\n", ui.LightCyan(path))
if err := p.sendJUnitReport(uploadPath, xmlData); err != nil {
return errors.Wrapf(err, "failed to send JUnit report %s", stat.Name())
Expand Down

0 comments on commit 4aba7f8

Please sign in to comment.