mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
ensure we don't try to run another test when lazygit is invoked as a daemon
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/app"
|
"github.com/jesseduffield/lazygit/pkg/app"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/app/daemon"
|
||||||
"github.com/jesseduffield/lazygit/pkg/integration"
|
"github.com/jesseduffield/lazygit/pkg/integration"
|
||||||
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
||||||
)
|
)
|
||||||
@ -30,13 +32,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getIntegrationTest() integrationTypes.IntegrationTest {
|
func getIntegrationTest() integrationTypes.IntegrationTest {
|
||||||
integrationTestName := os.Getenv("LAZYGIT_TEST_NAME")
|
if daemon.InDaemonMode() {
|
||||||
if integrationTestName == "" {
|
// if we've invoked lazygit as a daemon from within lazygit,
|
||||||
panic("expected LAZYGIT_TEST_NAME environment variable to be set, given that we're running an integration test")
|
// 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 {
|
for _, candidateTest := range integration.Tests {
|
||||||
if candidateTest.Name() == integrationTestName {
|
if candidateTest.Name() == integrationTestName {
|
||||||
return candidateTest
|
return candidateTest
|
||||||
|
@ -38,6 +38,8 @@ const (
|
|||||||
SANDBOX
|
SANDBOX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const LAZYGIT_TEST_NAME_ENV_VAR = "LAZYGIT_TEST_NAME"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
logf func(format string, formatArgs ...interface{})
|
logf func(format string, formatArgs ...interface{})
|
||||||
)
|
)
|
||||||
@ -58,7 +60,7 @@ func RunTests(
|
|||||||
testDir := filepath.Join(rootDir, "test", "integration_new")
|
testDir := filepath.Join(rootDir, "test", "integration_new")
|
||||||
|
|
||||||
osCommand := oscommands.NewDummyOSCommand()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -270,7 +272,7 @@ func getLazygitCommand(test *components.IntegrationTest, testPath string, rootDi
|
|||||||
|
|
||||||
cmdObj := osCommand.Cmd.New(cmdStr)
|
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
|
return cmdObj.GetCmd(), nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user