2021-09-16 15:38:43 +02:00
|
|
|
//go:build !windows
|
2021-04-08 13:24:49 +02:00
|
|
|
// +build !windows
|
|
|
|
|
2022-08-14 06:33:44 +02:00
|
|
|
package clients
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2023-02-26 02:23:36 +02:00
|
|
|
// This file allows you to use `go test` to run integration tests.
|
|
|
|
// See See pkg/integration/README.md for more info.
|
2022-08-07 14:09:39 +02:00
|
|
|
|
2020-10-04 09:41:33 +02:00
|
|
|
import (
|
2022-09-10 06:11:05 +02:00
|
|
|
"bytes"
|
|
|
|
"errors"
|
2021-04-05 05:07:25 +02:00
|
|
|
"io"
|
2020-10-04 09:41:33 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2021-04-06 01:02:01 +02:00
|
|
|
"os/exec"
|
2020-10-04 09:41:33 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-04-05 05:07:25 +02:00
|
|
|
"github.com/creack/pty"
|
2022-08-12 01:24:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/integration/components"
|
2022-08-14 03:24:07 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/integration/tests"
|
2020-10-04 09:41:33 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-08-09 13:27:12 +02:00
|
|
|
func TestIntegration(t *testing.T) {
|
2022-06-11 04:42:16 +02:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration tests in short mode")
|
|
|
|
}
|
|
|
|
|
|
|
|
parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
|
|
|
|
parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
|
|
|
|
testNumber := 0
|
|
|
|
|
2022-08-14 03:24:07 +02:00
|
|
|
err := components.RunTests(
|
2022-08-14 12:32:17 +02:00
|
|
|
tests.GetTests(),
|
2021-04-06 01:02:01 +02:00
|
|
|
t.Logf,
|
|
|
|
runCmdHeadless,
|
2022-08-12 01:19:39 +02:00
|
|
|
func(test *components.IntegrationTest, f func() error) {
|
2022-06-11 04:42:16 +02:00
|
|
|
defer func() { testNumber += 1 }()
|
|
|
|
if testNumber%parallelTotal != parallelIndex {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-07 14:09:39 +02:00
|
|
|
t.Run(test.Name(), func(t *testing.T) {
|
2022-09-10 06:11:05 +02:00
|
|
|
t.Parallel()
|
2022-08-09 13:11:41 +02:00
|
|
|
err := f()
|
2020-10-05 11:55:15 +02:00
|
|
|
assert.NoError(t, err)
|
2021-04-06 01:02:01 +02:00
|
|
|
})
|
|
|
|
},
|
2022-12-20 13:40:14 +02:00
|
|
|
false,
|
2022-08-14 06:33:44 +02:00
|
|
|
0,
|
2022-09-17 07:31:46 +02:00
|
|
|
// allowing two attempts at the test. If a test fails intermittently,
|
|
|
|
// there may be a concurrency issue that we need to resolve.
|
|
|
|
2,
|
2021-04-06 01:02:01 +02:00
|
|
|
)
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2020-10-06 00:23:09 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
func runCmdHeadless(cmd *exec.Cmd) error {
|
|
|
|
cmd.Env = append(
|
|
|
|
cmd.Env,
|
|
|
|
"HEADLESS=true",
|
|
|
|
"TERM=xterm",
|
|
|
|
)
|
2020-10-06 00:23:09 +02:00
|
|
|
|
2022-09-10 06:11:05 +02:00
|
|
|
// not writing stderr to the pty because we want to capture a panic if
|
|
|
|
// there is one. But some commands will not be in tty mode if stderr is
|
|
|
|
// not a terminal. We'll need to keep an eye out for that.
|
|
|
|
stderr := new(bytes.Buffer)
|
|
|
|
cmd.Stderr = stderr
|
|
|
|
|
|
|
|
// these rows and columns are ignored because internally we use tcell's
|
|
|
|
// simulation screen. However we still need the pty for the sake of
|
|
|
|
// running other commands in a pty.
|
|
|
|
f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 300, Cols: 300})
|
2021-04-06 01:02:01 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
_, _ = io.Copy(ioutil.Discard, f)
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2022-09-10 06:11:05 +02:00
|
|
|
if cmd.Wait() != nil {
|
|
|
|
// return an error with the stderr output
|
|
|
|
return errors.New(stderr.String())
|
|
|
|
}
|
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
return f.Close()
|
2020-10-04 09:41:33 +02:00
|
|
|
}
|