Skip to content

Commit 74a4a66

Browse files
authored
[TT-1834] Uses Proper JSON Naming for Flakeguard (#1502)
* Uses proper JSON for flakeguard * Use proper JSON fields in decoding
1 parent 64f30d9 commit 74a4a66

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

tools/flakeguard/reports/data.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,44 @@ import (
88
"time"
99
)
1010

11-
// Data Structures
12-
11+
// TestReport reports on the parameters and results of one to many test runs
1312
type TestReport struct {
14-
GoProject string
15-
HeadSHA string
16-
BaseSHA string
17-
RepoURL string
18-
GitHubWorkflowName string
19-
TestRunCount int
20-
RaceDetection bool
21-
ExcludedTests []string
22-
SelectedTests []string
23-
Results []TestResult
13+
GoProject string `json:"go_project"`
14+
HeadSHA string `json:"head_sha"`
15+
BaseSHA string `json:"base_sha"`
16+
RepoURL string `json:"repo_url"`
17+
GitHubWorkflowName string `json:"github_workflow_name"`
18+
TestRunCount int `json:"test_run_count"`
19+
RaceDetection bool `json:"race_detection"`
20+
ExcludedTests []string `json:"excluded_tests"`
21+
SelectedTests []string `json:"selected_tests"`
22+
Results []TestResult `json:"results"`
2423
}
2524

25+
// TestResult contains the results and outputs of a single test
2626
type TestResult struct {
27-
TestName string
28-
TestPackage string
29-
PackagePanic bool
30-
Panic bool
31-
Timeout bool
32-
Race bool
33-
Skipped bool
34-
PassRatio float64
35-
Runs int
36-
Failures int
37-
Successes int
38-
Skips int
39-
Outputs map[string][]string `json:"-"` // Temporary storage for outputs during test run
40-
PassedOutputs map[string][]string // Outputs for passed runs
41-
FailedOutputs map[string][]string // Outputs for failed runs
42-
Durations []time.Duration
43-
PackageOutputs []string
44-
TestPath string
45-
CodeOwners []string
27+
TestName string `json:"test_name"`
28+
TestPackage string `json:"test_package"`
29+
PackagePanic bool `json:"package_panic"`
30+
Panic bool `json:"panic"`
31+
Timeout bool `json:"timeout"`
32+
Race bool `json:"race"`
33+
Skipped bool `json:"skipped"`
34+
PassRatio float64 `json:"pass_ratio"`
35+
Runs int `json:"runs"`
36+
Failures int `json:"failures"`
37+
Successes int `json:"successes"`
38+
Skips int `json:"skips"`
39+
Outputs map[string][]string `json:"-"` // Temporary storage for outputs during test run
40+
PassedOutputs map[string][]string `json:"passed_outputs"` // Outputs for passed runs
41+
FailedOutputs map[string][]string `json:"failed_outputs"` // Outputs for failed runs
42+
Durations []time.Duration `json:"durations"`
43+
PackageOutputs []string `json:"package_outputs"`
44+
TestPath string `json:"test_path"`
45+
CodeOwners []string `json:"code_owners"`
4646
}
4747

48+
// SummaryData contains aggregated data from a set of test results
4849
type SummaryData struct {
4950
TotalTests int `json:"total_tests"`
5051
PanickedTests int `json:"panicked_tests"`

tools/flakeguard/reports/io.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,52 +100,52 @@ func processLargeFile(filePath string, reportChan chan<- *TestReport, errChan ch
100100
}
101101

102102
switch fieldName {
103-
case "GoProject":
103+
case "go_project":
104104
if err := decoder.Decode(&report.GoProject); err != nil {
105105
log.Printf("Error decoding GoProject in file: %s, Error: %v", filePath, err)
106106
return
107107
}
108-
case "HeadSHA":
108+
case "head_sha":
109109
if err := decoder.Decode(&report.HeadSHA); err != nil {
110110
log.Printf("Error decoding HeadSHA in file: %s, Error: %v", filePath, err)
111111
return
112112
}
113-
case "BaseSHA":
113+
case "base_sha":
114114
if err := decoder.Decode(&report.BaseSHA); err != nil {
115115
log.Printf("Error decoding BaseSHA in file: %s, Error: %v", filePath, err)
116116
return
117117
}
118-
case "RepoURL":
118+
case "repo_url":
119119
if err := decoder.Decode(&report.RepoURL); err != nil {
120120
log.Printf("Error decoding RepoURL in file: %s, Error: %v", filePath, err)
121121
return
122122
}
123-
case "GitHubWorkflowName":
123+
case "github_workflow_name":
124124
if err := decoder.Decode(&report.GitHubWorkflowName); err != nil {
125125
log.Printf("Error decoding GitHubWorkflowName in file: %s, Error: %v", filePath, err)
126126
return
127127
}
128-
case "TestRunCount":
128+
case "test_run_count":
129129
if err := decoder.Decode(&report.TestRunCount); err != nil {
130130
log.Printf("Error decoding TestRunCount in file: %s, Error: %v", filePath, err)
131131
return
132132
}
133-
case "RaceDetection":
133+
case "race_detection":
134134
if err := decoder.Decode(&report.RaceDetection); err != nil {
135135
log.Printf("Error decoding RaceDetection in file: %s, Error: %v", filePath, err)
136136
return
137137
}
138-
case "ExcludedTests":
138+
case "excluded_tests":
139139
if err := decoder.Decode(&report.ExcludedTests); err != nil {
140140
log.Printf("Error decoding ExcludedTests in file: %s, Error: %v", filePath, err)
141141
return
142142
}
143-
case "SelectedTests":
143+
case "selected_tests":
144144
if err := decoder.Decode(&report.SelectedTests); err != nil {
145145
log.Printf("Error decoding SelectedTests in file: %s, Error: %v", filePath, err)
146146
return
147147
}
148-
case "Results":
148+
case "results":
149149
token, err := decoder.Token() // Read opening bracket '['
150150
if err != nil || token != json.Delim('[') {
151151
log.Printf("Error reading Results array start in file: %s, Error: %v", filePath, err)
@@ -172,7 +172,7 @@ func processLargeFile(filePath string, reportChan chan<- *TestReport, errChan ch
172172
log.Printf("Error skipping unknown field: %s in file: %s, Error: %v", fieldName, filePath, err)
173173
return
174174
}
175-
log.Printf("Skipped unknown field: %s in file: %s", fieldName, filePath)
175+
log.Printf("Skipped unknown field: '%s' in file: %s", fieldName, filePath)
176176
}
177177
}
178178

tools/flakeguard/reports/presentation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func GeneratePRCommentMarkdown(w io.Writer, testReport *TestReport, maxPassRatio
146146
}
147147

148148
resultsTable := GenerateFlakyTestsTable(testReport.Results, maxPassRatio, true)
149-
renderTestResultsTable(w, resultsTable, true)
149+
renderTestResultsTable(w, resultsTable)
150150

151151
if artifactLink != "" {
152152
renderArtifactSection(w, artifactName, artifactLink)
@@ -179,7 +179,7 @@ func RenderResults(
179179
resultsTable := GenerateFlakyTestsTable(tests, maxPassRatio, markdown)
180180
summary := GenerateSummaryData(tests, maxPassRatio)
181181
renderSummaryTable(w, summary, markdown)
182-
renderTestResultsTable(w, resultsTable, markdown)
182+
renderTestResultsTable(w, resultsTable)
183183
}
184184

185185
func renderSummaryTable(w io.Writer, summary SummaryData, markdown bool) {
@@ -209,7 +209,7 @@ func renderSummaryTable(w io.Writer, summary SummaryData, markdown bool) {
209209
fmt.Fprintln(w)
210210
}
211211

212-
func renderTestResultsTable(w io.Writer, table [][]string, markdown bool) {
212+
func renderTestResultsTable(w io.Writer, table [][]string) {
213213
if len(table) <= 1 {
214214
fmt.Fprintln(w, "No tests found under the specified pass ratio threshold.")
215215
return

0 commit comments

Comments
 (0)