1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Add GitVersion field to NewIntegrationTestArgs

It can be used to specify which git versions a given test should or should not run on.
This commit is contained in:
Stefan Haller
2023-04-13 23:14:56 +02:00
parent 227b0b781c
commit a304fed68c
4 changed files with 149 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"path/filepath"
"github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
)
@ -42,6 +43,11 @@ func RunTests(
return err
}
gitVersion, err := getGitVersion()
if err != nil {
return err
}
for _, test := range tests {
test := test
@ -51,7 +57,7 @@ func RunTests(
)
for i := 0; i < maxAttempts; i++ {
err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, keyPressDelay)
err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, keyPressDelay, gitVersion)
if err != nil {
if i == maxAttempts-1 {
return err
@ -77,12 +83,18 @@ func runTest(
runCmd func(cmd *exec.Cmd) error,
sandbox bool,
keyPressDelay int,
gitVersion *git_commands.GitVersion,
) error {
if test.Skip() {
logf("Skipping test %s", test.Name())
return nil
}
if !test.ShouldRunForGitVersion(gitVersion) {
logf("Skipping test %s for git version %d.%d.%d", test.Name(), gitVersion.Major, gitVersion.Minor, gitVersion.Patch)
return nil
}
logf("path: %s", paths.Root())
if err := prepareTestDir(test, paths, projectRootDir); err != nil {
@ -144,6 +156,16 @@ func globalGitConfigPath(rootDir string) string {
return filepath.Join(rootDir, "test", "global_git_config")
}
func getGitVersion() (*git_commands.GitVersion, error) {
osCommand := oscommands.NewDummyOSCommand()
cmdObj := osCommand.Cmd.New("git --version")
versionStr, err := cmdObj.RunWithOutput()
if err != nil {
return nil, err
}
return git_commands.ParseGitVersion(versionStr)
}
func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandbox bool, keyPressDelay int) (*exec.Cmd, error) {
osCommand := oscommands.NewDummyOSCommand()