@@ -10,6 +10,7 @@ import (
1010 "github.com/rs/zerolog/log"
1111 "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
1212 "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/runner"
13+ "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/utils"
1314 "github.com/spf13/cobra"
1415)
1516
@@ -35,15 +36,16 @@ var RunTestsCmd = &cobra.Command{
3536
3637 // Retrieve flags
3738 projectPath , _ := cmd .Flags ().GetString ("project-path" )
39+ codeownersPath , _ := cmd .Flags ().GetString ("codeowners-path" )
3840 testPackagesJson , _ := cmd .Flags ().GetString ("test-packages-json" )
3941 testPackagesArg , _ := cmd .Flags ().GetStringSlice ("test-packages" )
4042 testCmdStrings , _ := cmd .Flags ().GetStringArray ("test-cmd" )
4143 runCount , _ := cmd .Flags ().GetInt ("run-count" )
4244 rerunFailedCount , _ := cmd .Flags ().GetInt ("rerun-failed-count" )
4345 tags , _ := cmd .Flags ().GetStringArray ("tags" )
4446 useRace , _ := cmd .Flags ().GetBool ("race" )
45- mainReportPath , _ := cmd .Flags ().GetString ("main-report -path" )
46- rerunReportPath , _ := cmd .Flags ().GetString ("rerun-report -path" )
47+ mainResultsPath , _ := cmd .Flags ().GetString ("main-results -path" )
48+ rerunResultsPath , _ := cmd .Flags ().GetString ("rerun-results -path" )
4749 minPassRatio , _ := cmd .Flags ().GetFloat64 ("min-pass-ratio" )
4850 // For backward compatibility, check if max-pass-ratio was used
4951 maxPassRatio , _ := cmd .Flags ().GetFloat64 ("max-pass-ratio" )
@@ -57,6 +59,11 @@ var RunTestsCmd = &cobra.Command{
5759 failFast , _ := cmd .Flags ().GetBool ("fail-fast" )
5860 goTestTimeoutFlag , _ := cmd .Flags ().GetString ("go-test-timeout" )
5961
62+ goProject , err := utils .GetGoProjectName (projectPath )
63+ if err != nil {
64+ log .Warn ().Err (err ).Str ("projectPath" , goProject ).Msg ("Failed to get pretty project path" )
65+ }
66+
6067 // Retrieve go-test-count flag as a pointer if explicitly provided.
6168 var goTestCountFlag * int
6269 if cmd .Flags ().Changed ("go-test-count" ) {
@@ -124,45 +131,53 @@ var RunTestsCmd = &cobra.Command{
124131 FailFast : failFast ,
125132 }
126133
127- var (
128- mainReport * reports.TestReport // Main test report
129- rerunReport * reports.TestReport // Test report after rerunning failed tests
130- )
131-
132134 // Run the tests
133- var err error
135+ var mainResults []reports. TestResult
134136 if len (testCmdStrings ) > 0 {
135- mainReport , err = testRunner .RunTestCmd (testCmdStrings )
137+ mainResults , err = testRunner .RunTestCmd (testCmdStrings )
136138 if err != nil {
137139 log .Fatal ().Err (err ).Msg ("Error running custom test command" )
138140 flushSummaryAndExit (ErrorExitCode )
139141 }
140142 } else {
141- mainReport , err = testRunner .RunTestPackages (testPackages )
143+ mainResults , err = testRunner .RunTestPackages (testPackages )
142144 if err != nil {
143145 log .Fatal ().Err (err ).Msg ("Error running test packages" )
144146 flushSummaryAndExit (ErrorExitCode )
145147 }
146148 }
147149
148- // Save the main test report to file
149- if mainReportPath != "" && len (mainReport .Results ) > 0 {
150- if err := mainReport .SaveToFile (mainReportPath ); err != nil {
150+ if len (mainResults ) == 0 {
151+ log .Warn ().Msg ("No tests were run for the specified packages" )
152+ flushSummaryAndExit (0 )
153+ }
154+
155+ // Save the main test results to file
156+ if mainResultsPath != "" && len (mainResults ) > 0 {
157+ if err := reports .SaveTestResultsToFile (mainResults , mainResultsPath ); err != nil {
151158 log .Error ().Err (err ).Msg ("Error saving test results to file" )
152159 flushSummaryAndExit (ErrorExitCode )
153160 }
154- log .Info ().Str ("path" , mainReportPath ).Msg ("Main test report saved" )
161+ log .Info ().Str ("path" , mainResultsPath ).Msg ("Main test report saved" )
155162 }
156163
157- if len (mainReport .Results ) == 0 {
158- log .Warn ().Msg ("No tests were run for the specified packages" )
159- flushSummaryAndExit (0 )
164+ mainReport , err := reports .NewTestReport (mainResults ,
165+ reports .WithGoProject (goProject ),
166+ reports .WithCodeOwnersPath (codeownersPath ),
167+ reports .WithMaxPassRatio (passRatioThreshold ),
168+ reports .WithGoRaceDetection (useRace ),
169+ reports .WithExcludedTests (skipTests ),
170+ reports .WithSelectedTests (selectTests ),
171+ )
172+ if err != nil {
173+ log .Error ().Err (err ).Msg ("Error creating main test report" )
174+ flushSummaryAndExit (ErrorExitCode )
160175 }
161176
162177 // Accumulate main summary into summaryBuffer
163178 fmt .Fprint (& summaryBuffer , "\n Flakeguard Main Summary:\n " )
164179 fmt .Fprintf (& summaryBuffer , "-------------------------\n " )
165- reports .RenderResults (& summaryBuffer , * mainReport , false , false )
180+ reports .RenderTestReport (& summaryBuffer , mainReport , false , false )
166181 fmt .Fprintln (& summaryBuffer )
167182
168183 // Rerun failed tests
@@ -176,28 +191,41 @@ var RunTestsCmd = &cobra.Command{
176191 flushSummaryAndExit (0 )
177192 }
178193
179- rerunReport , err = testRunner .RerunFailedTests (failedTests )
194+ rerunResults , rerunJsonOutputPaths , err : = testRunner .RerunFailedTests (failedTests )
180195 if err != nil {
181196 log .Fatal ().Err (err ).Msg ("Error rerunning failed tests" )
182197 flushSummaryAndExit (ErrorExitCode )
183198 }
184199
200+ rerunReport , err := reports .NewTestReport (rerunResults ,
201+ reports .WithGoProject (goProject ),
202+ reports .WithCodeOwnersPath (codeownersPath ),
203+ reports .WithMaxPassRatio (1 ),
204+ reports .WithExcludedTests (skipTests ),
205+ reports .WithSelectedTests (selectTests ),
206+ reports .WithJSONOutputPaths (rerunJsonOutputPaths ),
207+ )
208+ if err != nil {
209+ log .Error ().Err (err ).Msg ("Error creating rerun test report" )
210+ flushSummaryAndExit (ErrorExitCode )
211+ }
212+
185213 fmt .Fprint (& summaryBuffer , "\n All Tests That Were Rerun:\n " )
186214 fmt .Fprintf (& summaryBuffer , "---------------------------\n " )
187215 reports .PrintTestResultsTable (& summaryBuffer , rerunReport .Results , false , false )
188216 fmt .Fprintln (& summaryBuffer )
189217
190218 // Save the rerun test report to file
191- if rerunReportPath != "" && len (rerunReport . Results ) > 0 {
192- if err := rerunReport . SaveToFile ( rerunReportPath ); err != nil {
219+ if rerunResultsPath != "" && len (rerunResults ) > 0 {
220+ if err := reports . SaveTestResultsToFile ( rerunResults , rerunResultsPath ); err != nil {
193221 log .Error ().Err (err ).Msg ("Error saving test results to file" )
194222 flushSummaryAndExit (ErrorExitCode )
195223 }
196- log .Info ().Str ("path" , rerunReportPath ).Msg ("Rerun test report saved" )
224+ log .Info ().Str ("path" , rerunResultsPath ).Msg ("Rerun test report saved" )
197225 }
198226
199227 // Filter tests that failed after reruns
200- failedAfterRerun := reports .FilterTests (rerunReport . Results , func (tr reports.TestResult ) bool {
228+ failedAfterRerun := reports .FilterTests (rerunResults , func (tr reports.TestResult ) bool {
201229 return ! tr .Skipped && tr .Successes == 0
202230 })
203231
@@ -246,6 +274,7 @@ var RunTestsCmd = &cobra.Command{
246274
247275func init () {
248276 RunTestsCmd .Flags ().StringP ("project-path" , "r" , "." , "The path to the Go project. Default is the current directory. Useful for subprojects" )
277+ RunTestsCmd .Flags ().StringP ("codeowners-path" , "" , "" , "Path to the CODEOWNERS file" )
249278 RunTestsCmd .Flags ().String ("test-packages-json" , "" , "JSON-encoded string of test packages" )
250279 RunTestsCmd .Flags ().StringSlice ("test-packages" , nil , "Comma-separated list of test packages to run" )
251280 RunTestsCmd .Flags ().StringArray ("test-cmd" , nil ,
@@ -260,8 +289,8 @@ func init() {
260289 RunTestsCmd .Flags ().Bool ("shuffle" , false , "Enable test shuffling" )
261290 RunTestsCmd .Flags ().String ("shuffle-seed" , "" , "Set seed for test shuffling. Must be used with --shuffle" )
262291 RunTestsCmd .Flags ().Bool ("fail-fast" , false , "Stop on the first test failure" )
263- RunTestsCmd .Flags ().String ("main-report -path" , "" , "Path to the main test report in JSON format" )
264- RunTestsCmd .Flags ().String ("rerun-report -path" , "" , "Path to the rerun test report in JSON format" )
292+ RunTestsCmd .Flags ().String ("main-results -path" , "" , "Path to the main test results in JSON format" )
293+ RunTestsCmd .Flags ().String ("rerun-results -path" , "" , "Path to the rerun test results in JSON format" )
265294 RunTestsCmd .Flags ().StringSlice ("skip-tests" , nil , "Comma-separated list of test names to skip from running" )
266295 RunTestsCmd .Flags ().StringSlice ("select-tests" , nil , "Comma-separated list of test names to specifically run" )
267296
0 commit comments