1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

ensure we don't try to run another test when lazygit is invoked as a daemon

This commit is contained in:
Jesse Duffield 2022-08-13 14:12:35 +10:00
parent 5e475355bf
commit cad84c9e74
2 changed files with 18 additions and 7 deletions

View File

@ -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

View File

@ -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
}