Skip to content

Commit 6e6e656

Browse files
committed
Markdown optional
1 parent e876f00 commit 6e6e656

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var RunTestsCmd = &cobra.Command{
7171
// Print all failed tests including flaky tests
7272
if printFailedTests {
7373
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n", maxPassRatio)
74-
reports.PrintResults(os.Stdout, testReport.Results, maxPassRatio, false)
74+
reports.PrintResults(os.Stdout, testReport.Results, maxPassRatio, false, false)
7575
}
7676

7777
// Save the test results in JSON format

tools/flakeguard/reports/reports.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func TestResultsTable(
174174
results []TestResult,
175175
expectedPassRatio float64,
176176
includeCodeOwners bool,
177+
markdown bool,
177178
) (resultsTable [][]string, runs, passes, fails, skips, panickedTests, racedTests, flakyTests int) {
178179
p := message.NewPrinter(language.English) // For formatting numbers
179180
sortTestResults(results)
@@ -196,6 +197,11 @@ func TestResultsTable(
196197
if includeCodeOwners {
197198
headers = append(headers, "Code Owners")
198199
}
200+
if markdown {
201+
for i, header := range headers {
202+
headers[i] = fmt.Sprintf("**%s**", header)
203+
}
204+
}
199205

200206
resultsTable = [][]string{}
201207
resultsTable = append(resultsTable, headers)
@@ -249,6 +255,7 @@ func PrintResults(
249255
w io.Writer,
250256
tests []TestResult,
251257
maxPassRatio float64,
258+
markdown bool,
252259
includeCodeOwners bool, // Include code owners in the output. Set to true if test results have code owners
253260
) (runs, passes, fails, skips, panickedTests, racedTests, flakyTests int) {
254261
var (
@@ -257,7 +264,7 @@ func PrintResults(
257264
flakeRatioStr string
258265
p = message.NewPrinter(language.English) // For formatting numbers
259266
)
260-
resultsTable, runs, passes, fails, skips, panickedTests, racedTests, flakyTests = TestResultsTable(tests, maxPassRatio, includeCodeOwners)
267+
resultsTable, runs, passes, fails, skips, panickedTests, racedTests, flakyTests = TestResultsTable(tests, maxPassRatio, markdown, includeCodeOwners)
261268
// Print out summary data
262269
if runs == 0 || passes == runs {
263270
passRatioStr = "100%"
@@ -283,6 +290,15 @@ func PrintResults(
283290
{"Skips", p.Sprint(skips)},
284291
{"Pass Ratio", passRatioStr},
285292
}
293+
if markdown {
294+
for i, row := range summaryData {
295+
if i == 0 {
296+
summaryData[i] = []string{"**Category**", "**Total**"}
297+
} else {
298+
summaryData[i] = []string{fmt.Sprintf("**%s**", row[0]), row[1]}
299+
}
300+
}
301+
}
286302

287303
colWidths := make([]int, len(summaryData[0]))
288304

@@ -401,7 +417,7 @@ func MarkdownSummary(w io.Writer, testReport *TestReport, maxPassRatio float64,
401417
return
402418
}
403419

404-
allRuns, passes, _, _, _, _, _ := PrintResults(testsData, tests, maxPassRatio, includeCodeOwners)
420+
allRuns, passes, _, _, _, _, _ := PrintResults(testsData, tests, maxPassRatio, true, includeCodeOwners)
405421
if allRuns > 0 {
406422
avgPassRatio = float64(passes) / float64(allRuns)
407423
}

tools/flakeguard/reports/reports_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestPrintTests(t *testing.T) {
142142
t.Parallel()
143143
var buf bytes.Buffer
144144

145-
runs, passes, fails, skips, panickedTests, racedTests, flakyTests := PrintResults(&buf, tc.testResults, tc.maxPassRatio, false)
145+
runs, passes, fails, skips, panickedTests, racedTests, flakyTests := PrintResults(&buf, tc.testResults, tc.maxPassRatio, false, false)
146146
assert.Equal(t, tc.expectedRuns, runs, "wrong number of runs")
147147
assert.Equal(t, tc.expectedPasses, passes, "wrong number of passes")
148148
assert.Equal(t, tc.expectedFails, fails, "wrong number of failures")

0 commit comments

Comments
 (0)