1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-21 21:47:32 +02:00
This commit is contained in:
Jesse Duffield 2022-08-11 21:28:55 +10:00
parent 1ef6f4c0e1
commit 610eddfe05
15 changed files with 64 additions and 40 deletions

@ -46,14 +46,14 @@ jobs:
# we're passing -short so that we skip the integration tests, which will be run in parallel below
run: |
go test ./... -short
integration-tests:
integration-tests-old:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
parallelism: [5]
index: [0,1,2,3,4]
name: "Integration Tests (${{ matrix.index }}/${{ matrix.parallelism }})"
name: "Integration Tests (Old pattern) (${{ matrix.index }}/${{ matrix.parallelism }})"
env:
GOFLAGS: -mod=vendor
steps:
@ -74,7 +74,31 @@ jobs:
${{runner.os}}-go-
- name: Test code
run: |
PARALLEL_TOTAL=${{ matrix.parallelism }} PARALLEL_INDEX=${{ matrix.index }} go test pkg/gui/gui_test.go
PARALLEL_TOTAL=${{ matrix.parallelism }} PARALLEL_INDEX=${{ matrix.index }} go test pkg/integration/deprecated/*.go
integration-tests:
runs-on: ubuntu-latest
name: "Integration Tests"
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
~/go/pkg/mod
key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-test
restore-keys: |
${{runner.os}}-go-
- name: Test code
run: |
go test pkg/integration/*.go
build:
runs-on: ubuntu-latest
env:

@ -22,7 +22,7 @@ import (
// This package is for running our integration test suite. See https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.mdfor more info.
type Test struct {
type IntegrationTest struct {
Name string `json:"name"`
Speed float64 `json:"speed"`
Description string `json:"description"`
@ -66,7 +66,7 @@ func GetModeFromEnv() Mode {
func RunTests(
logf func(format string, formatArgs ...interface{}),
runCmd func(cmd *exec.Cmd) error,
fnWrapper func(test *Test, f func(*testing.T) error),
fnWrapper func(test *IntegrationTest, f func(*testing.T) error),
mode Mode,
speedEnv string,
onFail func(t *testing.T, expected string, actual string, prefix string),
@ -315,13 +315,13 @@ func getTestSpeeds(testStartSpeed float64, mode Mode, speedStr string) []float64
return speeds
}
func LoadTests(testDir string) ([]*Test, error) {
func LoadTests(testDir string) ([]*IntegrationTest, error) {
paths, err := filepath.Glob(filepath.Join(testDir, "/*/test.json"))
if err != nil {
return nil, err
}
tests := make([]*Test, len(paths))
tests := make([]*IntegrationTest, len(paths))
for i, path := range paths {
data, err := ioutil.ReadFile(path)
@ -329,7 +329,7 @@ func LoadTests(testDir string) ([]*Test, error) {
return nil, err
}
test := &Test{}
test := &IntegrationTest{}
err = json.Unmarshal(data, test)
if err != nil {

@ -16,7 +16,7 @@ import (
"github.com/stretchr/testify/assert"
)
// Deprecated: this is the old way of running tests. See pkg/gui/gui_test.go for the new way.
// Deprecated.
// This file is quite similar to integration/main.go. The main difference is that this file is
// run via `go test` whereas the other is run via `test/lazyintegration/main.go` which provides
@ -40,7 +40,7 @@ import (
// trying at the original playback speed (speed 1). A speed of 2 represents twice the
// original playback speed. Speed may be a decimal.
func TestOld(t *testing.T) {
func Test(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration tests in short mode")
}
@ -56,7 +56,7 @@ func TestOld(t *testing.T) {
err := RunTests(
t.Logf,
runCmdHeadless,
func(test *Test, f func(*testing.T) error) {
func(test *IntegrationTest, f func(*testing.T) error) {
defer func() { testNumber += 1 }()
if testNumber%parallelTotal != parallelIndex {
return

@ -30,7 +30,7 @@ func main() {
err := deprecated.RunTests(
log.Printf,
runCmdInTerminal,
func(test *deprecated.Test, f func(*testing.T) error) {
func(test *deprecated.IntegrationTest, f func(*testing.T) error) {
if selectedTestName != "" && test.Name != selectedTestName {
return
}

@ -19,14 +19,14 @@ import (
// this program lets you manage integration tests in a TUI. See https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md for more info.
type App struct {
tests []*deprecated.Test
tests []*deprecated.IntegrationTest
itemIdx int
testDir string
editing bool
g *gocui.Gui
}
func (app *App) getCurrentTest() *deprecated.Test {
func (app *App) getCurrentTest() *deprecated.IntegrationTest {
if len(app.tests) > 0 {
return app.tests[app.itemIdx]
}

@ -12,7 +12,7 @@ import (
// Test describes an integration tests that will be run against the lazygit gui.
type Test struct {
type IntegrationTest struct {
name string
description string
extraCmdArgs string
@ -27,9 +27,9 @@ type Test struct {
)
}
var _ integrationTypes.IntegrationTest = &Test{}
var _ integrationTypes.IntegrationTest = &IntegrationTest{}
type NewTestArgs struct {
type NewIntegrationTestArgs struct {
// Briefly describes what happens in the test and what it's testing for
Description string
// prepares a repo for testing
@ -44,8 +44,8 @@ type NewTestArgs struct {
Skip bool
}
func NewTest(args NewTestArgs) *Test {
return &Test{
func NewIntegrationTest(args NewIntegrationTestArgs) *IntegrationTest {
return &IntegrationTest{
name: testNameFromFilePath(),
description: args.Description,
extraCmdArgs: args.ExtraCmdArgs,
@ -56,32 +56,32 @@ func NewTest(args NewTestArgs) *Test {
}
}
func (self *Test) Name() string {
func (self *IntegrationTest) Name() string {
return self.name
}
func (self *Test) Description() string {
func (self *IntegrationTest) Description() string {
return self.description
}
func (self *Test) ExtraCmdArgs() string {
func (self *IntegrationTest) ExtraCmdArgs() string {
return self.extraCmdArgs
}
func (self *Test) Skip() bool {
func (self *IntegrationTest) Skip() bool {
return self.skip
}
func (self *Test) SetupConfig(config *config.AppConfig) {
func (self *IntegrationTest) SetupConfig(config *config.AppConfig) {
self.setupConfig(config)
}
func (self *Test) SetupRepo(shell *Shell) {
func (self *IntegrationTest) SetupRepo(shell *Shell) {
self.setupRepo(shell)
}
// I want access to all contexts, the model, the ability to press a key, the ability to log,
func (self *Test) Run(gui integrationTypes.GuiAdapter) {
func (self *IntegrationTest) Run(gui integrationTypes.GuiAdapter) {
shell := NewShell()
assert := NewAssert(gui)
keys := gui.Keys()

@ -45,7 +45,7 @@ type (
func RunTests(
logf logf,
runCmd func(cmd *exec.Cmd) error,
fnWrapper func(test *helpers.Test, f func() error),
fnWrapper func(test *helpers.IntegrationTest, f func() error),
mode Mode,
includeSkipped bool,
) error {
@ -229,7 +229,7 @@ func compareSnapshots(logf logf, configDir string, actualDir string, expectedDir
return nil
}
func createFixture(test *helpers.Test, actualDir string, rootDir string) error {
func createFixture(test *helpers.IntegrationTest, actualDir string, rootDir string) error {
if err := os.Chdir(actualDir); err != nil {
panic(err)
}
@ -249,7 +249,7 @@ func createFixture(test *helpers.Test, actualDir string, rootDir string) error {
return nil
}
func getLazygitCommand(test *helpers.Test, testPath string, rootDir string) (*exec.Cmd, error) {
func getLazygitCommand(test *helpers.IntegrationTest, testPath string, rootDir string) (*exec.Cmd, error) {
osCommand := oscommands.NewDummyOSCommand()
templateConfigDir := filepath.Join(rootDir, "test", "default_test_config")

@ -34,7 +34,7 @@ func TestIntegration(t *testing.T) {
err := RunTests(
t.Logf,
runCmdHeadless,
func(test *helpers.Test, f func() error) {
func(test *helpers.IntegrationTest, f func() error) {
defer func() { testNumber += 1 }()
if testNumber%parallelTotal != parallelIndex {
return

@ -17,7 +17,7 @@ import (
func main() {
mode := integration.GetModeFromEnv()
includeSkipped := os.Getenv("INCLUDE_SKIPPED") == "true"
var testsToRun []*helpers.Test
var testsToRun []*helpers.IntegrationTest
if len(os.Args) > 1 {
outer:
@ -35,14 +35,14 @@ func main() {
testsToRun = integration.Tests
}
testNames := slices.Map(testsToRun, func(test *helpers.Test) string {
testNames := slices.Map(testsToRun, func(test *helpers.IntegrationTest) string {
return test.Name()
})
err := integration.RunTests(
log.Printf,
runCmdInTerminal,
func(test *helpers.Test, f func() error) {
func(test *helpers.IntegrationTest, f func() error) {
if !slices.Contains(testNames, test.Name()) {
return
}

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers"
)
var Suggestions = helpers.NewTest(helpers.NewTestArgs{
var Suggestions = helpers.NewIntegrationTest(helpers.NewIntegrationTestArgs{
Description: "Checking out a branch with name suggestions",
ExtraCmdArgs: "",
Skip: false,

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers"
)
var Commit = helpers.NewTest(helpers.NewTestArgs{
var Commit = helpers.NewIntegrationTest(helpers.NewIntegrationTestArgs{
Description: "Staging a couple files and committing",
ExtraCmdArgs: "",
Skip: false,

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers"
)
var NewBranch = helpers.NewTest(helpers.NewTestArgs{
var NewBranch = helpers.NewIntegrationTest(helpers.NewIntegrationTestArgs{
Description: "Creating a new branch from a commit",
ExtraCmdArgs: "",
Skip: false,

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers"
)
var One = helpers.NewTest(helpers.NewTestArgs{
var One = helpers.NewIntegrationTest(helpers.NewIntegrationTestArgs{
Description: "Begins an interactive rebase, then fixups, drops, and squashes some commits",
ExtraCmdArgs: "",
Skip: false,

@ -10,7 +10,7 @@ import (
// Here is where we lists the actual tests that will run. When you create a new test,
// be sure to add it to this list.
var Tests = []*helpers.Test{
var Tests = []*helpers.IntegrationTest{
commit.Commit,
commit.NewBranch,
branch.Suggestions,

@ -18,14 +18,14 @@ import (
// this program lets you manage integration tests in a TUI. See pkg/integration/README.md for more info.
type App struct {
tests []*helpers.Test
tests []*helpers.IntegrationTest
itemIdx int
testDir string
filtering bool
g *gocui.Gui
}
func (app *App) getCurrentTest() *helpers.Test {
func (app *App) getCurrentTest() *helpers.IntegrationTest {
if len(app.tests) > 0 {
return app.tests[app.itemIdx]
}