Skip to content

Commit

Permalink
remove old integration test recording code
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Mar 24, 2023
1 parent 4b67a45 commit 8121a0c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 253 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
github.com/jesseduffield/gocui v0.3.1-0.20230319043340-e793609bfbf5
github.com/jesseduffield/gocui v0.3.1-0.20230324073941-36f2e87458fa
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE=
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
github.com/jesseduffield/gocui v0.3.1-0.20230319043340-e793609bfbf5 h1:8k7VTfj/RSKwYQ7Cn+iy876CjixBrTyyn+npxT/Wn/Q=
github.com/jesseduffield/gocui v0.3.1-0.20230319043340-e793609bfbf5/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
github.com/jesseduffield/gocui v0.3.1-0.20230324073941-36f2e87458fa h1:E9G1mj94rMal1YLaABwdxLUUgKq+xGbElFjHRNaDJUg=
github.com/jesseduffield/gocui v0.3.1-0.20230324073941-36f2e87458fa/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=
Expand Down
25 changes: 2 additions & 23 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gui
import (
"fmt"
"io"
"log"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -436,17 +435,9 @@ var RuneReplacements = map[rune]string{
}

func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest) (*gocui.Gui, error) {
recordEvents := RecordingEvents()
playMode := gocui.NORMAL
if recordEvents {
playMode = gocui.RECORDING
} else if Replaying() {
playMode = gocui.REPLAYING
} else if test != nil && os.Getenv(components.SANDBOX_ENV_VAR) != "true" {
playMode = gocui.REPLAYING_NEW
}
playRecording := test != nil && os.Getenv(components.SANDBOX_ENV_VAR) != "true"

g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless, RuneReplacements)
g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playRecording, headless, RuneReplacements)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -577,10 +568,6 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
}
}

if err := SaveRecording(gui.g.Recording); err != nil {
return err
}

return nil

default:
Expand Down Expand Up @@ -611,14 +598,6 @@ func (gui *Gui) runSubprocessWithSuspense(subprocess oscommands.ICmdObj) (bool,
gui.Mutexes.SubprocessMutex.Lock()
defer gui.Mutexes.SubprocessMutex.Unlock()

if Replaying() {
// we do not yet support running subprocesses within integration tests. So if
// we're replaying an integration test and we're inside this method, something
// has gone wrong, so we should fail

log.Fatal("opening subprocesses not yet supported in integration tests. Chances are that this test is running too fast and a subprocess is accidentally opened")
}

if err := gui.g.Suspend(); err != nil {
return false, gui.c.Error(err)
}
Expand Down
81 changes: 0 additions & 81 deletions pkg/gui/test_mode.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package gui

import (
"encoding/json"
"log"
"os"
"strconv"
"time"

"github.com/jesseduffield/gocui"
Expand Down Expand Up @@ -42,87 +40,8 @@ func (gui *Gui) handleTestMode(test integrationTypes.IntegrationTest) {
log.Fatal("40 seconds is up, lazygit recording took too long to complete")
})
}

if Replaying() {
gui.g.RecordingConfig = gocui.RecordingConfig{
Speed: GetRecordingSpeed(),
Leeway: 1000,
}

var err error
gui.g.Recording, err = 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")
})
}
}

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 := os.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 os.WriteFile(path, jsonEvents, 0o600)
}
2 changes: 1 addition & 1 deletion pkg/integration/clients/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func RunTUI() {
app := newApp(testDir)
app.loadTests()

g, err := gocui.NewGui(gocui.OutputTrue, false, gocui.NORMAL, false, gui.RuneReplacements)
g, err := gocui.NewGui(gocui.OutputTrue, false, false, false, gui.RuneReplacements)
if err != nil {
log.Panicln(err)
}
Expand Down
6 changes: 4 additions & 2 deletions scripts/bump_gocui.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

# Go's proxy servers are not very up-to-date so that's why we use `GOPROXY=direct`
# We specify the `awesome` branch to avoid the default behaviour of looking for a semver tag.
GOPROXY=direct go get -u github.com/jesseduffield/gocui@awesome && go mod vendor && go mod tidy
# We specify the `master` branch to avoid the default behaviour of looking for a semver tag.
GOPROXY=direct go get -u github.com/jesseduffield/gocui@master && go mod vendor && go mod tidy

# Note to self if you ever want to fork a repo be sure to use this same approach: it's important to use the branch name (e.g. master)
127 changes: 4 additions & 123 deletions vendor/github.com/jesseduffield/gocui/gui.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8121a0c

Please sign in to comment.