Atlas › Test

TestGenerateTestReportTable

Exact test identity: go.temporal.io/server/tools/flakereport/TestGenerateTestReportTable

Package
go.temporal.io/server/tools/flakereport
Suite / test hierarchy
TestGenerateTestReportTable
Test
TestGenerateTestReportTable
Introduced at
report.go ×4 Frontier kind: Joint frontier
Covered ranges
11
Covered lines
50
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/tools/flakereport/report.go 50 covered LOC · 11 ranges

Open complete file

13
14 // hoursAgo formats a timestamp as "Xh ago" relative to now.
15 > func hoursAgo(t time.Time) string { report.go
16 > h := math.Round(time.Since(t).Hours())
17 > if h < 1 {
18 h = 1
19 }
20 > return fmt.Sprintf("%dh ago", int(h)) report.go
21 }
22
36
37 // formatLinks formats GitHub URLs as numbered markdown links
38 > func formatLinks(urls []string, maxLinks int) string { report.go
39 > linkCount := min(len(urls), maxLinks)
40 > var parts []string
41 > for i := range linkCount {
42 > parts = append(parts, fmt.Sprintf("[%d](%s)", i+1, urls[i]))
43 > }
44 > return strings.Join(parts, " ")
45 }
46
47 > func formatSparkline(points []int) string { report.go
48 > if len(points) == 0 {
49 return "-"
50 }
51
52 > maxPoint := 0 report.go
53 > for _, point := range points {
54 > if point > maxPoint {
55 > maxPoint = point
56 > }
57 }
58 > var sb strings.Builder report.go
59 > sb.Grow(len(points))
60 > for _, point := range points {
61 > if point == 0 {
62 > sb.WriteRune(sparklineRunes[0])
63 > continue
64 }
65 > idx := int(math.Ceil(float64(point) / float64(maxPoint) * float64(len(sparklineRunes)-1))) report.go
66 > sb.WriteRune(sparklineRunes[idx])
67 }
68 > return sb.String() report.go
69 }
70
95
96 // generateTestReportTable creates a markdown table of test reports with rate column.
97 > func generateTestReportTable(reports []TestReport, rateHeader string, maxLinks int) string { report.go
98 > if len(reports) == 0 {
99 return ""
100 }
101
102 > var sb strings.Builder report.go
103 > sb.WriteString(fmt.Sprintf("| Test | %s | Last Failure | Trend | Links |\n", rateHeader))
104 > sb.WriteString("|------|------------|-------------|-------|-------|\n")
105 >
106 > for _, report := range reports {
107 > pct := 0.0
108 > if report.TotalRuns > 0 {
109 > pct = float64(report.FailureCount) / float64(report.TotalRuns) * 100.0
110 > }
111 > links := formatLinks(report.GitHubURLs, maxLinks)
112 > lastFailure := "N/A"
113 > if !report.LastFailure.IsZero() {
114 > lastFailure = hoursAgo(report.LastFailure)
115 > }
116 > rate := fmt.Sprintf("%.1f%% (%d/%d)", pct, report.FailureCount, report.TotalRuns)
117 > if pct > boldFlakeRateThreshold {
118 > rate = "**" + rate + "**"
119 > }
120 > sb.WriteString(fmt.Sprintf("| `%s` | %s | %s | `%s` | %s |\n",
121 > report.TestName, rate, lastFailure, formatSparkline(report.TrendPoints), links))
122 }
123
124 > return sb.String() report.go
125 }