@@ -91,8 +91,8 @@ func FilterSkippedTests(results []TestResult) []TestResult {
9191 return skippedTests
9292}
9393
94- // AggregateTestResults aggregates all JSON test results .
95- func AggregateTestResults ( folderPath string ) (* TestReport , error ) {
94+ // AggregateTestReports aggregates multiple test reports into a single report .
95+ func AggregateTestReports ( reportsToAggregate ... * TestReport ) (* TestReport , error ) {
9696 var (
9797 // Map to hold unique tests based on their TestName and TestPackage
9898 // Key: TestName|TestPackage, Value: TestResult
@@ -103,67 +103,49 @@ func AggregateTestResults(folderPath string) (*TestReport, error) {
103103 )
104104
105105 // Read all JSON files in the folder
106- err := filepath .Walk (folderPath , func (path string , info os.FileInfo , err error ) error {
107- if err != nil {
108- return err
106+ for _ , report := range reportsToAggregate {
107+ if fullReport .GoProject == "" {
108+ fullReport .GoProject = report .GoProject
109+ } else if fullReport .GoProject != report .GoProject {
110+ return nil , fmt .Errorf ("reports with different Go projects found, expected %s, got %s" , fullReport .GoProject , report .GoProject )
109111 }
110- if ! info .IsDir () && filepath .Ext (path ) == ".json" {
111- // Read file content
112- data , readErr := os .ReadFile (path )
113- if readErr != nil {
114- return readErr
115- }
116- var report TestReport
117- if jsonErr := json .Unmarshal (data , & report ); jsonErr != nil {
118- return jsonErr
119- }
120- if fullReport .GoProject == "" {
121- fullReport .GoProject = report .GoProject
122- } else if fullReport .GoProject != report .GoProject {
123- return fmt .Errorf ("multiple projects found in the results folder, expected %s, got %s" , fullReport .GoProject , report .GoProject )
124- }
125- fullReport .TestRunCount += report .TestRunCount
126- fullReport .RaceDetection = report .RaceDetection && fullReport .RaceDetection
127- for _ , test := range report .ExcludedTests {
128- excludedTests [test ] = struct {}{}
129- }
130- for _ , test := range report .SelectedTests {
131- selectedTests [test ] = struct {}{}
132- }
133- // Process each test results
134- for _ , result := range report .Results {
135- // Unique key for each test based on TestName and TestPackage
136- key := result .TestName + "|" + result .TestPackage
137- if existingResult , found := testMap [key ]; found {
138- // Aggregate runs, durations, and outputs
139- existingResult .Runs = existingResult .Runs + result .Runs
140- existingResult .Durations = append (existingResult .Durations , result .Durations ... )
141- existingResult .Outputs = append (existingResult .Outputs , result .Outputs ... )
142- existingResult .PackageOutputs = append (existingResult .PackageOutputs , result .PackageOutputs ... )
143- existingResult .Successes += result .Successes
144- existingResult .Failures += result .Failures
145- existingResult .Panic = existingResult .Panic || result .Panic
146- existingResult .Race = existingResult .Race || result .Race
147- existingResult .Skips += result .Skips
148- existingResult .PassRatio = 1.0
149- if existingResult .Runs > 0 {
150- existingResult .PassRatio = float64 (existingResult .Successes ) / float64 (existingResult .Runs )
151- }
152-
153- existingResult .Skipped = existingResult .Skipped && result .Skipped // Mark as skipped only if all occurrences are skipped
154-
155- // Update the map with the aggregated result
156- testMap [key ] = existingResult
157- } else {
158- // Add new entry to the map
159- testMap [key ] = result
112+ fullReport .TestRunCount += report .TestRunCount
113+ fullReport .RaceDetection = report .RaceDetection && fullReport .RaceDetection
114+ for _ , test := range report .ExcludedTests {
115+ excludedTests [test ] = struct {}{}
116+ }
117+ for _ , test := range report .SelectedTests {
118+ selectedTests [test ] = struct {}{}
119+ }
120+ // Process each test results
121+ for _ , result := range report .Results {
122+ // Unique key for each test based on TestName and TestPackage
123+ key := result .TestName + "|" + result .TestPackage
124+ if existingResult , found := testMap [key ]; found {
125+ // Aggregate runs, durations, and outputs
126+ existingResult .Runs = existingResult .Runs + result .Runs
127+ existingResult .Durations = append (existingResult .Durations , result .Durations ... )
128+ existingResult .Outputs = append (existingResult .Outputs , result .Outputs ... )
129+ existingResult .PackageOutputs = append (existingResult .PackageOutputs , result .PackageOutputs ... )
130+ existingResult .Successes += result .Successes
131+ existingResult .Failures += result .Failures
132+ existingResult .Panic = existingResult .Panic || result .Panic
133+ existingResult .Race = existingResult .Race || result .Race
134+ existingResult .Skips += result .Skips
135+ existingResult .PassRatio = 1.0
136+ if existingResult .Runs > 0 {
137+ existingResult .PassRatio = float64 (existingResult .Successes ) / float64 (existingResult .Runs )
160138 }
139+
140+ existingResult .Skipped = existingResult .Skipped && result .Skipped // Mark as skipped only if all occurrences are skipped
141+
142+ // Update the map with the aggregated result
143+ testMap [key ] = existingResult
144+ } else {
145+ // Add new entry to the map
146+ testMap [key ] = result
161147 }
162148 }
163- return nil
164- })
165- if err != nil {
166- return nil , fmt .Errorf ("error reading files: %v" , err )
167149 }
168150 // Aggregate
169151 for test := range excludedTests {
0 commit comments