1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/test_mode.go

58 lines
1007 B
Go
Raw Normal View History

2022-08-07 14:09:39 +02:00
package gui
import (
"log"
"os"
2022-08-07 14:09:39 +02:00
"time"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/integration/components"
2022-08-07 14:09:39 +02:00
"github.com/jesseduffield/lazygit/pkg/utils"
)
2022-08-09 12:27:44 +02:00
type IntegrationTest interface {
Run(*GuiDriver)
2022-08-09 12:27:44 +02:00
}
func (gui *Gui) handleTestMode() {
test := gui.integrationTest
if os.Getenv(components.SANDBOX_ENV_VAR) == "true" {
return
}
if test != nil {
isIdleChan := make(chan struct{})
gui.c.GocuiGui().AddIdleListener(isIdleChan)
waitUntilIdle := func() {
<-isIdleChan
}
2022-08-07 14:09:39 +02:00
go func() {
waitUntilIdle()
2022-08-07 14:09:39 +02:00
test.Run(&GuiDriver{gui: gui, isIdleChan: isIdleChan})
2022-08-07 14:09:39 +02:00
gui.g.Update(func(*gocui.Gui) error {
return gocui.ErrQuit
})
waitUntilIdle()
2022-08-07 14:09:39 +02:00
time.Sleep(time.Second * 1)
log.Fatal("gocui should have already exited")
}()
go utils.Safe(func() {
time.Sleep(time.Second * 40)
log.Fatal("40 seconds is up, lazygit recording took too long to complete")
})
}
}
func Headless() bool {
return os.Getenv("HEADLESS") != ""
}