diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 09:02:01 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 19:34:32 +1000 |
commit | 440eb387d77d27ce5591e5fd8b4e0541d3f8e879 (patch) | |
tree | 97af8d612651ca30a7dcfa1eb77a283e3a4dd13c /test | |
parent | 28ffaf93488756f9d257d07e8b7eae9dbd9fb8ad (diff) |
much cleaner integration test code
Diffstat (limited to 'test')
-rw-r--r-- | test/lazyintegration/main.go | 8 | ||||
-rw-r--r-- | test/runner/main.go | 62 |
2 files changed, 67 insertions, 3 deletions
diff --git a/test/lazyintegration/main.go b/test/lazyintegration/main.go index 5fdc6ca82..4b3eba77d 100644 --- a/test/lazyintegration/main.go +++ b/test/lazyintegration/main.go @@ -13,6 +13,8 @@ import ( "github.com/jesseduffield/lazygit/pkg/secureexec" ) +// this program lets you manage integration tests in a TUI. + type App struct { tests []*integration.Test itemIdx int @@ -98,7 +100,7 @@ func main() { return nil } - cmd := secureexec.Command("sh", "-c", fmt.Sprintf("RECORD_EVENTS=true go run integration/main.go %s", currentTest.Name)) + cmd := secureexec.Command("sh", "-c", fmt.Sprintf("RECORD_EVENTS=true go run test/runner/main.go %s", currentTest.Name)) app.runSubprocess(cmd) return nil @@ -112,7 +114,7 @@ func main() { return nil } - cmd := secureexec.Command("sh", "-c", fmt.Sprintf("go run integration/main.go %s", currentTest.Name)) + cmd := secureexec.Command("sh", "-c", fmt.Sprintf("go run test/runner/main.go %s", currentTest.Name)) app.runSubprocess(cmd) return nil @@ -126,7 +128,7 @@ func main() { return nil } - cmd := secureexec.Command("sh", "-c", fmt.Sprintf("UPDATE_SNAPSHOTS=true go run integration/main.go %s", currentTest.Name)) + cmd := secureexec.Command("sh", "-c", fmt.Sprintf("UPDATE_SNAPSHOTS=true go run test/runner/main.go %s", currentTest.Name)) app.runSubprocess(cmd) return nil diff --git a/test/runner/main.go b/test/runner/main.go new file mode 100644 index 000000000..54e163c48 --- /dev/null +++ b/test/runner/main.go @@ -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() +} |