diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f933ddb1b..c8ed88468 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,15 +10,52 @@ on: pull_request: jobs: - ci: + unit-tests: strategy: fail-fast: false matrix: os: - ubuntu-latest - windows-latest + include: + - os: ubuntu-latest + path: | + ~/.cache/go-build + ~/go/pkg/mod + - os: windows-latest + cache_path: ~\AppData\Local\go-build name: ci - ${{matrix.os}} runs-on: ${{matrix.os}} + 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@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: @@ -31,13 +68,15 @@ jobs: - name: Cache build uses: actions/cache@v1 with: - path: ~/.cache/go-build + path: | + ~/.cache/go-build + ~/go/pkg/mod key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-test restore-keys: | ${{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: @@ -53,7 +92,9 @@ jobs: - name: Cache build uses: actions/cache@v1 with: - path: ~/.cache/go-build + path: | + ~/.cache/go-build + ~/go/pkg/mod key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-build restore-keys: | ${{runner.os}}-go- @@ -81,7 +122,9 @@ jobs: - name: Cache build uses: actions/cache@v1 with: - path: ~/.cache/go-build + path: | + ~/.cache/go-build + ~/go/pkg/mod key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-build restore-keys: | ${{runner.os}}-go- @@ -102,7 +145,9 @@ jobs: - name: Cache build uses: actions/cache@v1 with: - path: ~/.cache/go-build + path: | + ~/.cache/go-build + ~/go/pkg/mod key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-test restore-keys: | ${{runner.os}}-go- 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 deleted file mode 100755 index d95a9b76e..000000000 --- a/test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -e -echo "" > coverage.txt - -export GOFLAGS=-mod=vendor - -use_go_test=false -if command -v gotest; then - use_go_test=true -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" - if [ "$use_go_test" == true ]; then - gotest $args - else - go test $args - fi - if [ -f profile.out ]; then - cat profile.out >> coverage.txt - rm profile.out - fi - fi -done