MCPcopy Create free account
hub / github.com/temporalio/temporal / parseJUnitFile

Function parseJUnitFile

tools/flakereport/parser.go:20–47  ·  view source on GitHub ↗

parseJUnitFile reads and parses a single JUnit XML file

(filePath string)

Source from the content-addressed store, hash-verified

18
19// parseJUnitFile reads and parses a single JUnit XML file
20func parseJUnitFile(filePath string) (*junit.Testsuites, error) {
21 file, err := os.Open(filePath)
22 if err != nil {
23 return nil, fmt.Errorf("failed to open file %s: %w", filePath, err)
24 }
25 defer func() {
26 if err := file.Close(); err != nil {
27 fmt.Printf("Warning: Failed to close file %s: %v\n", filePath, err)
28 }
29 }()
30
31 var testsuites junit.Testsuites
32 decoder := xml.NewDecoder(file)
33 if err := decoder.Decode(&testsuites); err != nil {
34 // Try parsing as a single testsuite
35 if _, seekErr := file.Seek(0, 0); seekErr != nil {
36 return nil, fmt.Errorf("failed to seek file %s: %w", filePath, seekErr)
37 }
38 var testsuite junit.Testsuite
39 decoder = xml.NewDecoder(file)
40 if err := decoder.Decode(&testsuite); err != nil {
41 return nil, fmt.Errorf("failed to parse JUnit XML %s: %w", filePath, err)
42 }
43 testsuites.Suites = []junit.Testsuite{testsuite}
44 }
45
46 return &testsuites, nil
47}
48
49// topLevelTestName extracts the suite/top-level test name from a test name.
50// For "TestSuiteV0/TestMethod" returns "TestSuiteV0".

Callers 1

processArtifactJobFunction · 0.85

Calls 5

NewDecoderMethod · 0.80
CloseMethod · 0.65
DecodeMethod · 0.65
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected