fix CI
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user