Skip to content

Commit 951da90

Browse files
committed
Refactor
1 parent 79a639b commit 951da90

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,8 @@ var RunTestsCmd = &cobra.Command{
159159
os.Exit(ErrorExitCode)
160160
}
161161

162-
// Filter tests that failed after reruns
163-
failedAfterRerun := reports.FilterTests(rerunReport.Results, func(tr reports.TestResult) bool {
164-
return !tr.Skipped && tr.Successes == 0
165-
})
166-
fmt.Printf("\nFlakeguard Rerun Summary:\n")
167-
reports.PrintTestTable(os.Stdout, *rerunReport, false, false)
162+
fmt.Printf("\nAll Rerun Tests:\n")
163+
reports.PrintTestResultsTable(os.Stdout, rerunReport.Results, false, false)
168164
fmt.Println()
169165

170166
// Save the rerun test report to file
@@ -176,14 +172,22 @@ var RunTestsCmd = &cobra.Command{
176172
log.Info().Str("path", rerunReportPath).Msg("Rerun test report saved")
177173
}
178174

175+
// Filter tests that failed after reruns
176+
failedAfterRerun := reports.FilterTests(rerunReport.Results, func(tr reports.TestResult) bool {
177+
return !tr.Skipped && tr.Successes == 0
178+
})
179+
179180
if len(failedAfterRerun) > 0 {
181+
fmt.Println("\nTests That Failed All Reruns:")
182+
reports.PrintTestResultsTable(os.Stdout, failedAfterRerun, false, false)
183+
fmt.Println()
180184
log.Error().
181-
Int("tests", len(failedAfterRerun)).
185+
Int("noSuccessTests", len(failedAfterRerun)).
182186
Int("reruns", rerunFailedCount).
183-
Msg("Tests still failing after reruns with 0 successes")
187+
Msg("Some tests are still failing after multiple reruns with no successful attempts.")
184188
os.Exit(ErrorExitCode)
185189
} else {
186-
log.Info().Msg("Tests that failed passed at least once after reruns")
190+
log.Info().Msg("All tests passed at least once after reruns")
187191
os.Exit(0)
188192
}
189193
} else {

tools/flakeguard/reports/presentation.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"golang.org/x/text/message"
1111
)
1212

13-
// generateTestTable is a helper that builds the table based on the given filter function.
14-
func generateTestTable(
15-
testReport TestReport,
13+
// generateTestResultsTable is a helper that builds the table based on the given filter function.
14+
func generateTestResultsTable(
15+
results []TestResult,
1616
markdown bool,
1717
filter func(result TestResult) bool,
1818
) [][]string {
@@ -45,7 +45,7 @@ func generateTestTable(
4545
// Initialize the table with headers
4646
table := [][]string{headers}
4747

48-
for _, result := range testReport.Results {
48+
for _, result := range results {
4949
if filter(result) {
5050
row := []string{
5151
result.TestName,
@@ -80,18 +80,18 @@ func GenerateFlakyTestsTable(
8080
testReport TestReport,
8181
markdown bool,
8282
) [][]string {
83-
return generateTestTable(testReport, markdown, func(result TestResult) bool {
83+
return generateTestResultsTable(testReport.Results, markdown, func(result TestResult) bool {
8484
return !result.Skipped && result.PassRatio < testReport.MaxPassRatio
8585
})
8686
}
8787

88-
// PrintTestTable prints a table with all test results.
89-
func PrintTestTable(
88+
// PrintTestResultsTable prints a table with all test results.
89+
func PrintTestResultsTable(
9090
w io.Writer,
91-
testReport TestReport,
91+
results []TestResult,
9292
markdown bool,
9393
collapsible bool) {
94-
table := generateTestTable(testReport, markdown, func(result TestResult) bool {
94+
table := generateTestResultsTable(results, markdown, func(result TestResult) bool {
9595
return true // Include all tests
9696
})
9797
printTable(w, table, collapsible)

0 commit comments

Comments
 (0)