mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-19 21:28:28 +02:00
run integration tests in parallel and properly cache windows build
This commit is contained in:
parent
32c0b39dbd
commit
02c5559704
39
.github/workflows/ci.yml
vendored
39
.github/workflows/ci.yml
vendored
@ -10,15 +10,50 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
unit-tests:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- windows-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}}
|
name: ci - ${{matrix.os}}
|
||||||
runs-on: ${{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:
|
env:
|
||||||
GOFLAGS: -mod=vendor
|
GOFLAGS: -mod=vendor
|
||||||
steps:
|
steps:
|
||||||
@ -37,7 +72,7 @@ jobs:
|
|||||||
${{runner.os}}-go-
|
${{runner.os}}-go-
|
||||||
- name: Test code
|
- name: Test code
|
||||||
run: |
|
run: |
|
||||||
bash ./test.sh
|
PARALLEL_TOTAL=${{ matrix.parallelism }} PARALLEL_INDEX=${{ matrix.index }} go test pkg/gui/gui_test.go
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
|
@ -7,34 +7,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestOSCommandRun(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
command string
|
command string
|
||||||
|
@ -10,6 +10,34 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestOSCommandOpenFileDarwin(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
filename string
|
filename string
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
@ -39,14 +40,27 @@ import (
|
|||||||
// original playback speed. Speed may be a decimal.
|
// original playback speed. Speed may be a decimal.
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("Skipping integration tests in short mode")
|
||||||
|
}
|
||||||
|
|
||||||
mode := integration.GetModeFromEnv()
|
mode := integration.GetModeFromEnv()
|
||||||
speedEnv := os.Getenv("SPEED")
|
speedEnv := os.Getenv("SPEED")
|
||||||
includeSkipped := os.Getenv("INCLUDE_SKIPPED") != ""
|
includeSkipped := os.Getenv("INCLUDE_SKIPPED") != ""
|
||||||
|
|
||||||
|
parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
|
||||||
|
parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
|
||||||
|
testNumber := 0
|
||||||
|
|
||||||
err := integration.RunTests(
|
err := integration.RunTests(
|
||||||
t.Logf,
|
t.Logf,
|
||||||
runCmdHeadless,
|
runCmdHeadless,
|
||||||
func(test *integration.Test, f func(*testing.T) error) {
|
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) {
|
t.Run(test.Name, func(t *testing.T) {
|
||||||
err := f(t)
|
err := f(t)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -80,3 +94,12 @@ func runCmdHeadless(cmd *exec.Cmd) error {
|
|||||||
|
|
||||||
return f.Close()
|
return f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tryConvert(numStr string, defaultVal int) int {
|
||||||
|
num, err := strconv.Atoi(numStr)
|
||||||
|
if err != nil {
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
2
test.sh
2
test.sh
@ -12,7 +12,7 @@ fi
|
|||||||
|
|
||||||
for d in $( find ./* -maxdepth 10 ! -path "./vendor*" ! -path "./.git*" ! -path "./scripts*" -type d); do
|
for d in $( find ./* -maxdepth 10 ! -path "./vendor*" ! -path "./.git*" ! -path "./scripts*" -type d); do
|
||||||
if ls $d/*.go &> /dev/null; then
|
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
|
if [ "$use_go_test" == true ]; then
|
||||||
gotest $args
|
gotest $args
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user