lazygit/pkg/gui/test_mode.go
2022-08-11 21:24:16 +10:00

68 lines
1.4 KiB
Go

package gui
import (
"fmt"
"log"
"time"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/integration"
"github.com/jesseduffield/lazygit/pkg/utils"
)
func (gui *Gui) handleTestMode() {
if integration.PlayingIntegrationTest() {
test, ok := integration.CurrentIntegrationTest()
if !ok {
panic(fmt.Sprintf("test %s not found", integration.IntegrationTestName()))
}
go func() {
time.Sleep(time.Millisecond * 100)
shell := &integration.ShellImpl{}
assert := &AssertImpl{gui: gui}
keys := gui.Config.GetUserConfig().Keybinding
input := NewInputImpl(gui, keys, assert, integration.KeyPressDelay())
test.Run(
shell,
input,
assert,
gui.c.UserConfig.Keybinding,
)
gui.g.Update(func(*gocui.Gui) error {
return gocui.ErrQuit
})
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")
})
}
if integration.Replaying() {
gui.g.RecordingConfig = gocui.RecordingConfig{
Speed: integration.GetRecordingSpeed(),
Leeway: 100,
}
var err error
gui.g.Recording, err = integration.LoadRecording()
if err != nil {
panic(err)
}
go utils.Safe(func() {
time.Sleep(time.Second * 40)
log.Fatal("40 seconds is up, lazygit recording took too long to complete")
})
}
}