summaryrefslogtreecommitdiffstats
path: root/pkg/gui/gui_test.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-10-05 20:55:15 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-10-10 00:23:01 +1100
commitdc953ea680ce2023459b9f4bf72f5ca423fb9c95 (patch)
tree67224d15415f84d1c3476e1d194e1681572af9e8 /pkg/gui/gui_test.go
parent08f8472db3b2942cbe5bfa977e10c4495ce242e3 (diff)
fall back to slower speed if test fails
Diffstat (limited to 'pkg/gui/gui_test.go')
-rw-r--r--pkg/gui/gui_test.go54
1 files changed, 34 insertions, 20 deletions
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go
index d9d43c7dc..b7c652a99 100644
--- a/pkg/gui/gui_test.go
+++ b/pkg/gui/gui_test.go
@@ -106,36 +106,48 @@ func Test(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
- testPath := filepath.Join(rootDir, "test", "integration", test.name)
- findOrCreateDir(testPath)
+ speeds := []int{10, 5, 1}
+ for i, speed := range speeds {
+ fmt.Printf("%s: trying again at speed %d\n", test.name, speed)
- snapshotPath := filepath.Join(testPath, "snapshot.txt")
+ testPath := filepath.Join(rootDir, "test", "integration", test.name)
+ findOrCreateDir(testPath)
- err := os.Chdir(rootDir)
- assert.NoError(t, err)
+ snapshotPath := filepath.Join(testPath, "snapshot.txt")
- prepareIntegrationTestDir()
+ err := os.Chdir(rootDir)
+ assert.NoError(t, err)
+
+ prepareIntegrationTestDir()
+
+ err = createFixture(rootDir, test.fixture)
+ assert.NoError(t, err)
- err = createFixture(rootDir, test.fixture)
- assert.NoError(t, err)
+ record := os.Getenv("RECORD_EVENTS") != ""
+ runLazygit(t, testPath, rootDir, record, speed)
- record := os.Getenv("RECORD_EVENTS") != ""
- runLazygit(t, testPath, rootDir, record)
+ updateSnapshot := record || os.Getenv("UPDATE_SNAPSHOT") != ""
- updateSnapshot := record || os.Getenv("UPDATE_SNAPSHOT") != ""
+ actual := generateSnapshot(t)
- actual := generateSnapshot(t)
+ if updateSnapshot {
+ err := ioutil.WriteFile(snapshotPath, []byte(actual), 0600)
+ assert.NoError(t, err)
+ }
- if updateSnapshot {
- err := ioutil.WriteFile(snapshotPath, []byte(actual), 0600)
+ expectedBytes, err := ioutil.ReadFile(snapshotPath)
assert.NoError(t, err)
- }
+ expected := string(expectedBytes)
- expectedBytes, err := ioutil.ReadFile(snapshotPath)
- assert.NoError(t, err)
- expected := string(expectedBytes)
+ if expected == actual {
+ break
+ }
- assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual))
+ // if the snapshots and we haven't tried all playback speeds different we'll retry at a slower speed
+ if i == len(speeds)-1 {
+ assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual))
+ }
+ }
})
}
}
@@ -169,7 +181,7 @@ func gotoRootDirectory() {
}
}
-func runLazygit(t *testing.T, testPath string, rootDir string, record bool) {
+func runLazygit(t *testing.T, testPath string, rootDir string, record bool, speed int) {
osCommand := oscommands.NewDummyOSCommand()
replayPath := filepath.Join(testPath, "recording.json")
@@ -193,6 +205,8 @@ func runLazygit(t *testing.T, testPath string, rootDir string, record bool) {
cmdStr = fmt.Sprintf("%s --use-config-dir=%s", cmdStr, configDir)
cmd := osCommand.ExecutableFromString(cmdStr)
+ cmd.Env = append(cmd.Env, fmt.Sprintf("REPLAY_SPEED=%d", speed))
+
if record {
cmd.Env = append(
cmd.Env,