diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-05 21:00:31 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-10 00:23:01 +1100 |
commit | 2724f3888a288aed1d5075465e7905cff1b8923e (patch) | |
tree | 987e7572ea4c39f39c6b4d578774b9634b26ff42 /pkg | |
parent | dc953ea680ce2023459b9f4bf72f5ca423fb9c95 (diff) |
fix CI
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/gui_test.go | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go index b7c652a99..cff8bce66 100644 --- a/pkg/gui/gui_test.go +++ b/pkg/gui/gui_test.go @@ -20,8 +20,8 @@ import ( // To record keypresses for an integration test, pass RECORD_EVENTS=true like so: // RECORD_EVENTS=true go test pkg/gui/gui_test.go -run /commit // -// To update a snapshot for an integration test, pass UPDATE_SNAPSHOT=true -// UPDATE_SNAPSHOT=true go test pkg/gui/gui_test.go -run /commit +// To update a snapshot for an integration test, pass UPDATE_SNAPSHOTS=true +// UPDATE_SNAPSHOTS=true go test pkg/gui/gui_test.go -run /commit // // When RECORD_EVENTS is true, updates will be updated automatically // @@ -71,7 +71,7 @@ func tests() []integrationTest { func generateSnapshot(t *testing.T) string { osCommand := oscommands.NewDummyOSCommand() - cmd := `sh -c "git status; cat ./*; git log --pretty=%B -p"` + cmd := `bash -c "git status; cat ./*; git log --pretty=%B -p"` snapshot, err := osCommand.RunCommandWithOutput(cmd) assert.NoError(t, err) @@ -103,12 +103,21 @@ func Test(t *testing.T) { panic(err) } + record := os.Getenv("RECORD_EVENTS") != "" + updateSnapshots := record || os.Getenv("UPDATE_SNAPSHOTS") != "" + for _, test := range tests { test := test + t.Run(test.name, func(t *testing.T) { speeds := []int{10, 5, 1} + if updateSnapshots { + // have to go at original speed if updating snapshots in case we go to fast and create a junk snapshot + speeds = []int{1} + } + for i, speed := range speeds { - fmt.Printf("%s: trying again at speed %d\n", test.name, speed) + t.Logf("%s: attempting test at speed %d\n", test.name, speed) testPath := filepath.Join(rootDir, "test", "integration", test.name) findOrCreateDir(testPath) @@ -123,14 +132,11 @@ func Test(t *testing.T) { err = createFixture(rootDir, test.fixture) assert.NoError(t, err) - record := os.Getenv("RECORD_EVENTS") != "" runLazygit(t, testPath, rootDir, record, speed) - updateSnapshot := record || os.Getenv("UPDATE_SNAPSHOT") != "" - actual := generateSnapshot(t) - if updateSnapshot { + if updateSnapshots { err := ioutil.WriteFile(snapshotPath, []byte(actual), 0600) assert.NoError(t, err) } @@ -154,7 +160,7 @@ func Test(t *testing.T) { func createFixture(rootDir string, name string) error { osCommand := oscommands.NewDummyOSCommand() - cmd := exec.Command("sh", filepath.Join(rootDir, "test", "fixtures", fmt.Sprintf("%s.sh", name))) + cmd := exec.Command("bash", filepath.Join(rootDir, "test", "fixtures", fmt.Sprintf("%s.sh", name))) if err := osCommand.RunExecutable(cmd); err != nil { return err @@ -226,8 +232,11 @@ func runLazygit(t *testing.T, testPath string, rootDir string, record bool, spee f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 100, Cols: 100}) assert.NoError(t, err) - _, err = io.Copy(os.Stdout, f) + _, _ = io.Copy(ioutil.Discard, f) + assert.NoError(t, err) + + _ = f.Close() } else { err := osCommand.RunExecutable(cmd) assert.NoError(t, err) |