diff --git a/pkg/integration/cmd/injector/main.go b/pkg/integration/cmd/injector/main.go index 9460c7b22..2f47d04a6 100644 --- a/pkg/integration/cmd/injector/main.go +++ b/pkg/integration/cmd/injector/main.go @@ -1,9 +1,11 @@ package main import ( + "fmt" "os" "github.com/jesseduffield/lazygit/pkg/app" + "github.com/jesseduffield/lazygit/pkg/app/daemon" "github.com/jesseduffield/lazygit/pkg/integration" integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" ) @@ -30,13 +32,20 @@ func main() { } func getIntegrationTest() integrationTypes.IntegrationTest { - integrationTestName := os.Getenv("LAZYGIT_TEST_NAME") - if integrationTestName == "" { - panic("expected LAZYGIT_TEST_NAME environment variable to be set, given that we're running an integration test") + if daemon.InDaemonMode() { + // if we've invoked lazygit as a daemon from within lazygit, + // we don't want to pass a test to the rest of the code. + return nil + } + + integrationTestName := os.Getenv(integration.LAZYGIT_TEST_NAME_ENV_VAR) + if integrationTestName == "" { + panic(fmt.Sprintf( + "expected %s environment variable to be set, given that we're running an integration test", + integration.LAZYGIT_TEST_NAME_ENV_VAR, + )) } - // unsetting so that if we run lazygit in as a 'daemon' we don't think we're trying to run a test again - os.Unsetenv("LAZYGIT_TEST_NAME") for _, candidateTest := range integration.Tests { if candidateTest.Name() == integrationTestName { return candidateTest diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index fd7b0fee6..ca71241e2 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -38,6 +38,8 @@ const ( SANDBOX ) +const LAZYGIT_TEST_NAME_ENV_VAR = "LAZYGIT_TEST_NAME" + type ( logf func(format string, formatArgs ...interface{}) ) @@ -58,7 +60,7 @@ func RunTests( testDir := filepath.Join(rootDir, "test", "integration_new") osCommand := oscommands.NewDummyOSCommand() - err = osCommand.Cmd.New(fmt.Sprintf("go build -o %s pkg/integration/cmd/injector.go", tempLazygitPath())).Run() + err = osCommand.Cmd.New(fmt.Sprintf("go build -o %s pkg/integration/cmd/injector/main.go", tempLazygitPath())).Run() if err != nil { return err } @@ -270,7 +272,7 @@ func getLazygitCommand(test *components.IntegrationTest, testPath string, rootDi cmdObj := osCommand.Cmd.New(cmdStr) - cmdObj.AddEnvVars(fmt.Sprintf("LAZYGIT_TEST_NAME=%s", test.Name())) + cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", LAZYGIT_TEST_NAME_ENV_VAR, test.Name())) return cmdObj.GetCmd(), nil }