diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go index d6cf5a628..80a482b5b 100644 --- a/pkg/integration/clients/cli.go +++ b/pkg/integration/clients/cli.go @@ -29,17 +29,17 @@ func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool, r inputDelay = SLOW_INPUT_DELAY } - err := components.RunTests( - getTestsToRun(testNames), - log.Printf, - runCmdInTerminal, - runAndPrintFatalError, - sandbox, - waitForDebugger, - raceDetector, - inputDelay, - 1, - ) + err := components.RunTests(components.RunTestArgs{ + Tests: getTestsToRun(testNames), + Logf: log.Printf, + RunCmd: runCmdInTerminal, + TestWrapper: runAndPrintFatalError, + Sandbox: sandbox, + WaitForDebugger: waitForDebugger, + RaceDetector: raceDetector, + InputDelay: inputDelay, + MaxAttempts: 1, + }) if err != nil { log.Print(err.Error()) } diff --git a/pkg/integration/clients/go_test.go b/pkg/integration/clients/go_test.go index 6503621ba..ec1999332 100644 --- a/pkg/integration/clients/go_test.go +++ b/pkg/integration/clients/go_test.go @@ -30,11 +30,11 @@ func TestIntegration(t *testing.T) { raceDetector := os.Getenv("LAZYGIT_RACE_DETECTOR") != "" testNumber := 0 - err := components.RunTests( - tests.GetTests(), - t.Logf, - runCmdHeadless, - func(test *components.IntegrationTest, f func() error) { + err := components.RunTests(components.RunTestArgs{ + Tests: tests.GetTests(), + Logf: t.Logf, + RunCmd: runCmdHeadless, + TestWrapper: func(test *components.IntegrationTest, f func() error) { defer func() { testNumber += 1 }() if testNumber%parallelTotal != parallelIndex { return @@ -52,13 +52,13 @@ func TestIntegration(t *testing.T) { assert.NoError(t, err) }) }, - false, - false, - raceDetector, - 0, + Sandbox: false, + WaitForDebugger: false, + RaceDetector: raceDetector, + InputDelay: 0, // Allow two attempts at each test to get around flakiness - 2, - ) + MaxAttempts: 2, + }) assert.NoError(t, err) } diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go index 7ad9cb47f..bcb4dfb4f 100644 --- a/pkg/integration/clients/tui.go +++ b/pkg/integration/clients/tui.go @@ -385,17 +385,17 @@ func quit(g *gocui.Gui, v *gocui.View) error { } func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, raceDetector bool, inputDelay int) { - err := components.RunTests( - []*components.IntegrationTest{test}, - log.Printf, - runCmdInTerminal, - runAndPrintError, - sandbox, - waitForDebugger, - raceDetector, - inputDelay, - 1, - ) + err := components.RunTests(components.RunTestArgs{ + Tests: []*components.IntegrationTest{test}, + Logf: log.Printf, + RunCmd: runCmdInTerminal, + TestWrapper: runAndPrintError, + Sandbox: sandbox, + WaitForDebugger: waitForDebugger, + RaceDetector: raceDetector, + InputDelay: inputDelay, + MaxAttempts: 1, + }) if err != nil { log.Println(err.Error()) } diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index d84ee4a22..4b8307981 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -20,21 +20,23 @@ const ( GIT_CONFIG_GLOBAL_ENV_VAR = "GIT_CONFIG_GLOBAL" ) +type RunTestArgs struct { + Tests []*IntegrationTest + Logf func(format string, formatArgs ...interface{}) + RunCmd func(cmd *exec.Cmd) (int, error) + TestWrapper func(test *IntegrationTest, f func() error) + Sandbox bool + WaitForDebugger bool + RaceDetector bool + InputDelay int + MaxAttempts int +} + // This function lets you run tests either from within `go test` or from a regular binary. // The reason for having two separate ways of testing is that `go test` isn't great at // showing what's actually happening during the test, but it's still good at running // tests in telling you about their results. -func RunTests( - tests []*IntegrationTest, - logf func(format string, formatArgs ...interface{}), - runCmd func(cmd *exec.Cmd) (int, error), - testWrapper func(test *IntegrationTest, f func() error), - sandbox bool, - waitForDebugger bool, - raceDetector bool, - inputDelay int, - maxAttempts int, -) error { +func RunTests(args RunTestArgs) error { projectRootDir := lazycoreUtils.GetLazyRootDirectory() err := os.Chdir(projectRootDir) if err != nil { @@ -42,8 +44,7 @@ func RunTests( } testDir := filepath.Join(projectRootDir, "test", "_results") - - if err := buildLazygit(waitForDebugger, raceDetector); err != nil { + if err := buildLazygit(args.WaitForDebugger, args.RaceDetector); err != nil { return err } @@ -52,21 +53,21 @@ func RunTests( return err } - for _, test := range tests { + for _, test := range args.Tests { test := test - testWrapper(test, func() error { //nolint: thelper + args.TestWrapper(test, func() error { //nolint: thelper paths := NewPaths( filepath.Join(testDir, test.Name()), ) - for i := 0; i < maxAttempts; i++ { - err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, raceDetector, inputDelay, gitVersion) + for i := 0; i < args.MaxAttempts; i++ { + err := runTest(test, paths, projectRootDir, args.Logf, args.RunCmd, args.Sandbox, args.WaitForDebugger, args.RaceDetector, args.InputDelay, gitVersion) if err != nil { - if i == maxAttempts-1 { + if i == args.MaxAttempts-1 { return err } - logf("retrying test %s", test.Name()) + args.Logf("retrying test %s", test.Name()) } else { break }