99 "testing"
1010
1111 "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
12+ "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/utils"
1213 "github.com/stretchr/testify/assert"
1314 "github.com/stretchr/testify/require"
1415)
@@ -42,15 +43,15 @@ type expectedTestResult struct {
4243func TestPrettyProjectPath (t * testing.T ) {
4344 t .Parallel ()
4445
45- prettyPath , err := prettyProjectPath ("./" )
46+ prettyPath , err := utils . GetGoProjectName ("./" )
4647 require .NoError (t , err )
4748 assert .Equal (t , "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard" , prettyPath )
4849}
4950
5051func TestRun (t * testing.T ) {
5152 var (
5253 zeroRuns = 0
53- oneRun = 1
54+ oneCount = 1
5455 successPassRate = 1.0
5556 failPassRate = 0.0
5657 )
@@ -184,6 +185,7 @@ func TestRun(t *testing.T) {
184185 Verbose : true ,
185186 RunCount : defaultTestRunCount ,
186187 GoTestRaceFlag : false ,
188+ GoTestCountFlag : & oneCount ,
187189 SkipTests : []string {},
188190 SelectTests : []string {"TestFlakyPanic" },
189191 FailFast : false ,
@@ -241,11 +243,11 @@ func TestRun(t *testing.T) {
241243 },
242244 expectedTests : map [string ]* expectedTestResult {
243245 "TestFail" : {
244- exactRuns : & oneRun ,
246+ exactRuns : & oneCount ,
245247 allFailures : true ,
246248 },
247249 "TestPass" : {
248- exactRuns : & oneRun ,
250+ exactRuns : & oneCount ,
249251 allSuccesses : true ,
250252 },
251253 },
@@ -254,7 +256,7 @@ func TestRun(t *testing.T) {
254256
255257 for _ , tc := range testCases {
256258 t .Run (tc .name , func (t * testing.T ) {
257- testReport , err := tc .runner .RunTestPackages ([]string {flakyTestPackagePath })
259+ testResults , err := tc .runner .RunTestPackages ([]string {flakyTestPackagePath })
258260 require .NoError (t , err )
259261
260262 t .Cleanup (func () {
@@ -267,7 +269,7 @@ func TestRun(t *testing.T) {
267269 }
268270 saniTName := strings .ReplaceAll (t .Name (), "/" , "_" )
269271 resultsFileName := filepath .Join (debugDir , fmt .Sprintf ("test_results_%s.json" , saniTName ))
270- jsonResults , err := json .Marshal (testReport )
272+ jsonResults , err := json .Marshal (testResults )
271273 if err != nil {
272274 t .Logf ("error marshalling test report: %v" , err )
273275 return
@@ -287,16 +289,8 @@ func TestRun(t *testing.T) {
287289 }
288290 })
289291
290- if tc .runner .FailFast {
291- require .Equal (t , 1 , testReport .SummaryData .TestRunCount , "unexpected number of unique tests run" )
292- } else {
293- require .Equal (t , tc .runner .RunCount , testReport .SummaryData .TestRunCount , "unexpected number of test runs" )
294- }
295-
296- require .Equal (t , tc .runner .GoTestRaceFlag , testReport .RaceDetection , "unexpected race usage" )
297-
298- assert .Equal (t , len (tc .expectedTests ), len (testReport .Results ), "unexpected number of test results" )
299- for _ , result := range testReport .Results {
292+ assert .Equal (t , len (tc .expectedTests ), len (testResults ), "unexpected number of test results" )
293+ for _ , result := range testResults {
300294 t .Run (fmt .Sprintf ("checking results of %s" , result .TestName ), func (t * testing.T ) {
301295 require .NotNil (t , result , "test result was nil" )
302296 expected , ok := tc .expectedTests [result .TestName ]
@@ -514,15 +508,15 @@ func TestFailedOutputs(t *testing.T) {
514508 CollectRawOutput : true ,
515509 }
516510
517- testReport , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
511+ testResults , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
518512 require .NoError (t , err , "running tests should not produce an unexpected error" )
519513
520- require .Equal (t , 1 , testReport . SummaryData . TotalRuns , "unexpected number of test runs" )
514+ require .Equal (t , 1 , len ( testResults ) , "unexpected number of test runs" )
521515
522516 var testFailResult * reports.TestResult
523- for i := range testReport . Results {
524- if testReport . Results [i ].TestName == "TestFail" {
525- testFailResult = & testReport . Results [i ]
517+ for i := range testResults {
518+ if testResults [i ].TestName == "TestFail" {
519+ testFailResult = & testResults [i ]
526520 break
527521 }
528522 }
@@ -537,68 +531,6 @@ func TestFailedOutputs(t *testing.T) {
537531 }
538532}
539533
540- func TestRerunFailed (t * testing.T ) {
541- t .Parallel ()
542-
543- // Configure a runner that will rerun failed tests
544- runner := Runner {
545- ProjectPath : "./" ,
546- Verbose : true ,
547- RunCount : 2 , // Run tests twice initially
548- RerunCount : 3 , // Rerun failing tests 3 more times
549- SelectTests : []string {"TestFail" }, // This test is known to always fail
550- CollectRawOutput : true ,
551- }
552-
553- testReport , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
554- require .NoError (t , err , "running tests should not produce an unexpected error" )
555-
556- // Verify we have the expected number of results
557- require .Equal (t , 1 , len (testReport .Results ), "expected exactly one test result" )
558-
559- // Find the TestFail result
560- var testFailResult * reports.TestResult
561- for i := range testReport .Results {
562- if testReport .Results [i ].TestName == "TestFail" {
563- testFailResult = & testReport .Results [i ]
564- break
565- }
566- }
567- require .NotNil (t , testFailResult , "expected TestFail result not found in report" )
568-
569- // TestFail should have run 5 times (2 initial + 3 reruns)
570- require .Equal (t , 5 , testFailResult .Runs , "TestFail should have run 5 times (2 initial + 3 reruns)" )
571-
572- // Verify that we have outputs from failed runs
573- require .NotEmpty (t , testFailResult .FailedOutputs , "expected failed outputs for TestFail" )
574- require .Empty (t , testFailResult .PassedOutputs , "TestFail should have no passed outputs" )
575-
576- // We should have outputs from both run and rerun prefixes
577- hasRunOutput := false
578- hasRerunOutput := false
579-
580- // Check if we have outputs from both original runs and reruns
581- for runID := range testFailResult .FailedOutputs {
582- t .Logf ("Found failed outputs for run %s" , runID )
583- if strings .HasPrefix (runID , "run" ) {
584- hasRunOutput = true
585- } else if strings .HasPrefix (runID , "rerun" ) {
586- hasRerunOutput = true
587- }
588- }
589-
590- require .True (t , hasRunOutput , "expected outputs from initial runs" )
591- require .True (t , hasRerunOutput , "expected outputs from reruns" )
592-
593- // Check that the PassRatio is 0 (since TestFail always fails)
594- require .Equal (t , 0.0 , testFailResult .PassRatio , "TestFail should have a pass ratio of 0.0" )
595-
596- // Verify that the test ran exactly 5 times and all were failures
597- require .Equal (t , 5 , testFailResult .Failures , "TestFail should have failed 5 times" )
598- require .Equal (t , 0 , testFailResult .Successes , "TestFail should have passed 0 times" )
599- require .Equal (t , 5 , testFailResult .Successes + testFailResult .Failures , "total of successes and failures should equal 5" )
600- }
601-
602534func TestSkippedTests (t * testing.T ) {
603535 t .Parallel ()
604536
@@ -610,17 +542,13 @@ func TestSkippedTests(t *testing.T) {
610542 CollectRawOutput : true ,
611543 }
612544
613- testReport , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
545+ testResults , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
614546 require .NoError (t , err , "running tests should not produce an unexpected error" )
615547
616- require .Equal (t , 0 , testReport .SummaryData .TotalRuns , "unexpected number of test runs" )
617- require .Equal (t , 1 , len (testReport .Results ), "unexpected number of test results" )
618- require .Equal (t , 0 , testReport .SummaryData .TestRunCount , "unexpected test run count" )
619-
620548 var testSkipResult * reports.TestResult
621- for i := range testReport . Results {
622- if testReport . Results [i ].TestName == "TestSkipped" {
623- testSkipResult = & testReport . Results [i ]
549+ for i := range testResults {
550+ if testResults [i ].TestName == "TestSkipped" {
551+ testSkipResult = & testResults [i ]
624552 break
625553 }
626554 }
@@ -645,15 +573,13 @@ func TestOmitOutputsOnSuccess(t *testing.T) {
645573 OmitOutputsOnSuccess : true ,
646574 }
647575
648- testReport , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
576+ testResults , err := runner .RunTestPackages ([]string {flakyTestPackagePath })
649577 require .NoError (t , err , "running tests should not produce an unexpected error" )
650578
651- require .Equal (t , 1 , testReport .SummaryData .TotalRuns , "unexpected number of test runs" )
652-
653579 var testPassResult * reports.TestResult
654- for i := range testReport . Results {
655- if testReport . Results [i ].TestName == "TestPass" {
656- testPassResult = & testReport . Results [i ]
580+ for i := range testResults {
581+ if testResults [i ].TestName == "TestPass" {
582+ testPassResult = & testResults [i ]
657583 break
658584 }
659585 }
0 commit comments