1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 16:22:24 +03:00

much cleaner integration test code

This commit is contained in:
Jesse Duffield
2021-04-06 09:02:01 +10:00
parent 28ffaf9348
commit 440eb387d7
5 changed files with 215 additions and 225 deletions

62
test/runner/main.go Normal file
View File

@@ -0,0 +1,62 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
"github.com/jesseduffield/lazygit/pkg/integration"
"github.com/stretchr/testify/assert"
)
// This file can be invoked directly, but you might find it easier to go through
// test/lazyintegration/main.go, which provides a convenient gui wrapper to integration
// tests.
//
// If invoked directly, you can specify a test by passing it as the first argument.
// You can also specify that you want to record a test by passing RECORD_EVENTS=true
// as an env var.
func main() {
record := os.Getenv("RECORD_EVENTS") != ""
updateSnapshots := record || os.Getenv("UPDATE_SNAPSHOTS") != ""
speedEnv := os.Getenv("SPEED")
selectedTestName := os.Args[1]
err := integration.RunTests(
log.Printf,
runCmdInTerminal,
func(test *integration.Test, f func() error) {
if selectedTestName != "" && test.Name != selectedTestName {
return
}
if err := f(); err != nil {
log.Print(err.Error())
}
},
updateSnapshots,
record,
speedEnv,
func(expected string, actual string) {
assert.Equal(MockTestingT{}, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual))
},
)
if err != nil {
log.Print(err.Error())
}
}
type MockTestingT struct{}
func (t MockTestingT) Errorf(format string, args ...interface{}) {
fmt.Printf(format, args...)
}
func runCmdInTerminal(cmd *exec.Cmd) error {
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
return cmd.Run()
}