summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-06-11 12:42:16 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-06-11 13:06:29 +1000
commit02c5559704a9d46c4740f939781d142e8ce08298 (patch)
treefc9a3bfed70015c682e352987b19610fd6c59d0d
parent32c0b39dbd3de89eb5fcc85efcef764c62311472 (diff)
run integration tests in parallel and properly cache windows build
-rw-r--r--.github/workflows/ci.yml39
-rw-r--r--pkg/commands/oscommands/os_test.go28
-rw-r--r--pkg/commands/oscommands/os_test_default.go28
-rw-r--r--pkg/gui/gui_test.go23
-rwxr-xr-xtest.sh2
5 files changed, 89 insertions, 31 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f933ddb1b..721228000 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,13 +10,18 @@ on:
pull_request:
jobs:
- ci:
+ unit-tests:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
+ include:
+ - os: ubuntu-latest
+ cache_path: ~/.cache/go-build
+ - os: windows-latest
+ cache_path: ~\AppData\Local\go-build
name: ci - ${{matrix.os}}
runs-on: ${{matrix.os}}
env:
@@ -29,6 +34,36 @@ jobs:
with:
go-version: 1.18.x
- name: Cache build
+ uses: actions/cache@v3
+ with:
+ path: |
+ ${{matrix.cache_path}}
+ ~/go/pkg/mod
+ key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-test
+ restore-keys: |
+ ${{runner.os}}-go-
+ - name: Test code
+ # we're passing -short so that we skip the integration tests, which will be run in parallel below
+ run: |
+ go test ./... -short
+ integration-tests:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ parallelism: [5]
+ index: [0,1,2,3,4]
+ name: "Integration Tests (${{ matrix.index }}/${{ matrix.parallelism }})"
+ env:
+ GOFLAGS: -mod=vendor
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ - name: Setup Go
+ uses: actions/setup-go@v1
+ with:
+ go-version: 1.18.x
+ - name: Cache build
uses: actions/cache@v1
with:
path: ~/.cache/go-build
@@ -37,7 +72,7 @@ jobs:
${{runner.os}}-go-
- name: Test code
run: |
- bash ./test.sh
+ PARALLEL_TOTAL=${{ matrix.parallelism }} PARALLEL_INDEX=${{ matrix.index }} go test pkg/gui/gui_test.go
build:
runs-on: ubuntu-latest
env:
diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go
index 9b289ea0a..0152fec58 100644
--- a/pkg/commands/oscommands/os_test.go
+++ b/pkg/commands/oscommands/os_test.go
@@ -7,34 +7,6 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestOSCommandRunWithOutput(t *testing.T) {
- type scenario struct {
- command string
- test func(string, error)
- }
-
- scenarios := []scenario{
- {
- "echo -n '123'",
- func(output string, err error) {
- assert.NoError(t, err)
- assert.EqualValues(t, "123", output)
- },
- },
- {
- "rmdir unexisting-folder",
- func(output string, err error) {
- assert.Regexp(t, "rmdir.*unexisting-folder.*", err.Error())
- },
- },
- }
-
- for _, s := range scenarios {
- c := NewDummyOSCommand()
- s.test(c.Cmd.New(s.command).RunWithOutput())
- }
-}
-
func TestOSCommandRun(t *testing.T) {
type scenario struct {
command string
diff --git a/pkg/commands/oscommands/os_test_default.go b/pkg/commands/oscommands/os_test_default.go
index f4c1221ed..39a1226d2 100644
--- a/pkg/commands/oscommands/os_test_default.go
+++ b/pkg/commands/oscommands/os_test_default.go
@@ -10,6 +10,34 @@ import (
"github.com/stretchr/testify/assert"
)
+func TestOSCommandRunWithOutput(t *testing.T) {
+ type scenario struct {
+ command string
+ test func(string, error)
+ }
+
+ scenarios := []scenario{
+ {
+ "echo -n '123'",
+ func(output string, err error) {
+ assert.NoError(t, err)
+ assert.EqualValues(t, "123", output)
+ },
+ },
+ {
+ "rmdir unexisting-folder",
+ func(output string, err error) {
+ assert.Regexp(t, "rmdir.*unexisting-folder.*", err.Error())
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ c := NewDummyOSCommand()
+ s.test(c.Cmd.New(s.command).RunWithOutput())
+ }
+}
+
func TestOSCommandOpenFileDarwin(t *testing.T) {
type scenario struct {
filename string
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go
index 58f0b0958..d2345d5d0 100644
--- a/pkg/gui/gui_test.go
+++ b/pkg/gui/gui_test.go
@@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"os/exec"
+ "strconv"
"testing"
"github.com/creack/pty"
@@ -39,14 +40,27 @@ import (
// original playback speed. Speed may be a decimal.
func Test(t *testing.T) {
+ if testing.Short() {
+ t.Skip("Skipping integration tests in short mode")
+ }
+
mode := integration.GetModeFromEnv()
speedEnv := os.Getenv("SPEED")
includeSkipped := os.Getenv("INCLUDE_SKIPPED") != ""
+ parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
+ parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
+ testNumber := 0
+
err := integration.RunTests(
t.Logf,
runCmdHeadless,
func(test *integration.Test, f func(*testing.T) error) {
+ defer func() { testNumber += 1 }()
+ if testNumber%parallelTotal != parallelIndex {
+ return
+ }
+
t.Run(test.Name, func(t *testing.T) {
err := f(t)
assert.NoError(t, err)
@@ -80,3 +94,12 @@ func runCmdHeadless(cmd *exec.Cmd) error {
return f.Close()
}
+
+func tryConvert(numStr string, defaultVal int) int {
+ num, err := strconv.Atoi(numStr)
+ if err != nil {
+ return defaultVal
+ }
+
+ return num
+}
diff --git a/test.sh b/test.sh
index d95a9b76e..0e202434e 100755
--- a/test.sh
+++ b/test.sh
@@ -12,7 +12,7 @@ fi
for d in $( find ./* -maxdepth 10 ! -path "./vendor*" ! -path "./.git*" ! -path "./scripts*" -type d); do
if ls $d/*.go &> /dev/null; then
- args="-race -v -coverprofile=profile.out -covermode=atomic $d"
+ args="-race -coverprofile=profile.out -covermode=atomic $d $@"
if [ "$use_go_test" == true ]; then
gotest $args
else