diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-08-09 21:11:41 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-08-13 13:52:13 +1000 |
commit | d890238c7bcbdd62e7158df0c1f3f0e5c0b05b66 (patch) | |
tree | e753258bc980b968bee27eaf97c7566c5c317923 /pkg/gui/test_mode.go | |
parent | 46ae55f91e4feab67b01fcd63631dbaf47b3665f (diff) |
move input and assert into integration tests package
Diffstat (limited to 'pkg/gui/test_mode.go')
-rw-r--r-- | pkg/gui/test_mode.go | 88 |
1 files changed, 75 insertions, 13 deletions
diff --git a/pkg/gui/test_mode.go b/pkg/gui/test_mode.go index 0252aa198..942e7824e 100644 --- a/pkg/gui/test_mode.go +++ b/pkg/gui/test_mode.go @@ -1,12 +1,15 @@ package gui import ( - "fmt" + "encoding/json" + "io/ioutil" "log" + "os" + "strconv" "time" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/integration" + "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -14,14 +17,8 @@ type IntegrationTest interface { Run(guiAdapter *GuiAdapterImpl) } -func (gui *Gui) handleTestMode() { - if integration.PlayingIntegrationTest() { - test, ok := integration.CurrentIntegrationTest() - - if !ok { - panic(fmt.Sprintf("test %s not found", integration.IntegrationTestName())) - } - +func (gui *Gui) handleTestMode(test types.Test) { + if test != nil { go func() { time.Sleep(time.Millisecond * 100) @@ -42,14 +39,14 @@ func (gui *Gui) handleTestMode() { }) } - if integration.Replaying() { + if Replaying() { gui.g.RecordingConfig = gocui.RecordingConfig{ - Speed: integration.GetRecordingSpeed(), + Speed: GetRecordingSpeed(), Leeway: 100, } var err error - gui.g.Recording, err = integration.LoadRecording() + gui.g.Recording, err = LoadRecording() if err != nil { panic(err) } @@ -60,3 +57,68 @@ func (gui *Gui) handleTestMode() { }) } } + +func Headless() bool { + return os.Getenv("HEADLESS") != "" +} + +// OLD integration test format stuff + +func Replaying() bool { + return os.Getenv("REPLAY_EVENTS_FROM") != "" +} + +func RecordingEvents() bool { + return recordEventsTo() != "" +} + +func recordEventsTo() string { + return os.Getenv("RECORD_EVENTS_TO") +} + +func GetRecordingSpeed() float64 { + // humans are slow so this speeds things up. + speed := 1.0 + envReplaySpeed := os.Getenv("SPEED") + if envReplaySpeed != "" { + var err error + speed, err = strconv.ParseFloat(envReplaySpeed, 64) + if err != nil { + log.Fatal(err) + } + } + return speed +} + +func LoadRecording() (*gocui.Recording, error) { + path := os.Getenv("REPLAY_EVENTS_FROM") + + data, err := ioutil.ReadFile(path) + if err != nil { + return nil, err + } + + recording := &gocui.Recording{} + + err = json.Unmarshal(data, &recording) + if err != nil { + return nil, err + } + + return recording, nil +} + +func SaveRecording(recording *gocui.Recording) error { + if !RecordingEvents() { + return nil + } + + jsonEvents, err := json.Marshal(recording) + if err != nil { + return err + } + + path := recordEventsTo() + + return ioutil.WriteFile(path, jsonEvents, 0o600) +} |