Skip to content

Commit

Permalink
flakeguard: Pretty print failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl committed Nov 4, 2024
1 parent c53b6e0 commit 6bf9fa8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tools/flakeguard/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ var RunTestsCmd = &cobra.Command{
skippedTests := reports.FilterSkippedTests(testResults)

if len(failedTests) > 0 {
jsonData, err := json.MarshalIndent(failedTests, "", " ")
if err != nil {
log.Fatalf("Error marshaling test results to JSON: %v", err)
}
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n%d failed tests:\n%s\n", threshold, len(failedTests), string(jsonData))
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n", threshold)
fmt.Printf("%d failed tests:\n", len(failedTests))
reports.PrintTests(failedTests)
}

fmt.Printf("Summary: %d passed, %d skipped, %d failed\n", len(passedTests), len(skippedTests), len(failedTests))
Expand Down
23 changes: 23 additions & 0 deletions tools/flakeguard/reports/reports.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package reports

import (
"fmt"
"strings"
)

type TestResult struct {
TestName string
TestPackage string
Expand Down Expand Up @@ -42,3 +47,21 @@ func FilterSkippedTests(results []TestResult) []TestResult {
}
return skippedTests
}

// PrintTests prints tests in a pretty format
func PrintTests(tests []TestResult) {
for i, test := range tests {
fmt.Printf("\n--- Test %d ---\n", i+1)
fmt.Printf("TestName: %s\n", test.TestName)
fmt.Printf("TestPackage: %s\n", test.TestPackage)
fmt.Printf("PassRatio: %.2f\n", test.PassRatio)
fmt.Printf("Skipped: %v\n", test.Skipped)
fmt.Printf("Runs: %d\n", test.Runs)
durationsStr := make([]string, len(test.Durations))
for i, duration := range test.Durations {
durationsStr[i] = fmt.Sprintf("%.2fs", duration)
}
fmt.Printf("Durations: %s\n", strings.Join(durationsStr, ", "))
fmt.Printf("Outputs:\n%s\n", strings.Join(test.Outputs, ""))
}
}

0 comments on commit 6bf9fa8

Please sign in to comment.