1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

Merge pull request #1991 from jesseduffield/parallel-tests

This commit is contained in:
Jesse Duffield 2022-06-11 13:17:36 +10:00 committed by GitHub
commit 2864366e95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 102 additions and 60 deletions

View File

@ -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-

View File

@ -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

View File

@ -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

View File

@ -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
}

26
test.sh
View File

@ -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