1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-25 22:01:14 +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

View File

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

View File

@ -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. // 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"` Name string `json:"name"`
Speed float64 `json:"speed"` Speed float64 `json:"speed"`
Description string `json:"description"` Description string `json:"description"`
@ -66,7 +66,7 @@ func GetModeFromEnv() Mode {
func RunTests( func RunTests(
logf func(format string, formatArgs ...interface{}), logf func(format string, formatArgs ...interface{}),
runCmd func(cmd *exec.Cmd) error, 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, mode Mode,
speedEnv string, speedEnv string,
onFail func(t *testing.T, expected string, actual string, prefix 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 return speeds
} }
func LoadTests(testDir string) ([]*Test, error) { func LoadTests(testDir string) ([]*IntegrationTest, error) {
paths, err := filepath.Glob(filepath.Join(testDir, "/*/test.json")) paths, err := filepath.Glob(filepath.Join(testDir, "/*/test.json"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
tests := make([]*Test, len(paths)) tests := make([]*IntegrationTest, len(paths))
for i, path := range paths { for i, path := range paths {
data, err := ioutil.ReadFile(path) data, err := ioutil.ReadFile(path)
@ -329,7 +329,7 @@ func LoadTests(testDir string) ([]*Test, error) {
return nil, err return nil, err
} }
test := &Test{} test := &IntegrationTest{}
err = json.Unmarshal(data, test) err = json.Unmarshal(data, test)
if err != nil { if err != nil {

View File

@ -16,7 +16,7 @@ import (
"github.com/stretchr/testify/assert" "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 // 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 // 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 // trying at the original playback speed (speed 1). A speed of 2 represents twice the
// original playback speed. Speed may be a decimal. // original playback speed. Speed may be a decimal.
func TestOld(t *testing.T) { func Test(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("Skipping integration tests in short mode") t.Skip("Skipping integration tests in short mode")
} }
@ -56,7 +56,7 @@ func TestOld(t *testing.T) {
err := RunTests( err := RunTests(
t.Logf, t.Logf,
runCmdHeadless, runCmdHeadless,
func(test *Test, f func(*testing.T) error) { func(test *IntegrationTest, f func(*testing.T) error) {
defer func() { testNumber += 1 }() defer func() { testNumber += 1 }()
if testNumber%parallelTotal != parallelIndex { if testNumber%parallelTotal != parallelIndex {
return return

View File

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

View File

@ -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. // 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 { type App struct {
tests []*deprecated.Test tests []*deprecated.IntegrationTest
itemIdx int itemIdx int
testDir string testDir string
editing bool editing bool
g *gocui.Gui g *gocui.Gui
} }
func (app *App) getCurrentTest() *deprecated.Test { func (app *App) getCurrentTest() *deprecated.IntegrationTest {
if len(app.tests) > 0 { if len(app.tests) > 0 {
return app.tests[app.itemIdx] return app.tests[app.itemIdx]
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers" "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", Description: "Checking out a branch with name suggestions",
ExtraCmdArgs: "", ExtraCmdArgs: "",
Skip: false, Skip: false,

View File

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers" "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", Description: "Staging a couple files and committing",
ExtraCmdArgs: "", ExtraCmdArgs: "",
Skip: false, Skip: false,

View File

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers" "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", Description: "Creating a new branch from a commit",
ExtraCmdArgs: "", ExtraCmdArgs: "",
Skip: false, Skip: false,

View File

@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/helpers" "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", Description: "Begins an interactive rebase, then fixups, drops, and squashes some commits",
ExtraCmdArgs: "", ExtraCmdArgs: "",
Skip: false, Skip: false,

View File

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

View File

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