From 6bf9fa8f4b67a44d4a0e7da81dbfee589e355591 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:41:04 +0100 Subject: [PATCH] flakeguard: Pretty print failed tests --- tools/flakeguard/cmd/run.go | 8 +++----- tools/flakeguard/reports/reports.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/flakeguard/cmd/run.go b/tools/flakeguard/cmd/run.go index f538e3f41..66ac9c6a2 100644 --- a/tools/flakeguard/cmd/run.go +++ b/tools/flakeguard/cmd/run.go @@ -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)) diff --git a/tools/flakeguard/reports/reports.go b/tools/flakeguard/reports/reports.go index bdfd63688..283f3ad27 100644 --- a/tools/flakeguard/reports/reports.go +++ b/tools/flakeguard/reports/reports.go @@ -1,5 +1,10 @@ package reports +import ( + "fmt" + "strings" +) + type TestResult struct { TestName string TestPackage string @@ -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, "")) + } +}