diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2021-05-12 10:45:53 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2021-05-12 10:45:53 +0300 |
commit | 421f6a52fdaf50d989e6a2120163846a2ec91f88 (patch) | |
tree | b291ebd17c5977e1fb0ed6b6ae332b67a3756b85 | |
parent | 8d525bfb986a26ee6c1c6d0ec976fa2614928cf8 (diff) | |
parent | c0f88d78711d70943c937323d404063b6cb854dc (diff) |
Merge branch 'ps-refactor-must-run-command' into 'master'
MustRunCommand should not be used for git commands execution
See merge request gitlab-org/gitaly!3480
-rw-r--r-- | internal/gitaly/service/repository/archive_test.go | 2 | ||||
-rw-r--r-- | internal/testhelper/configure.go | 4 | ||||
-rw-r--r-- | internal/testhelper/testhelper.go | 34 |
3 files changed, 8 insertions, 32 deletions
diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go index b5688e59b..8d037f649 100644 --- a/internal/gitaly/service/repository/archive_test.go +++ b/internal/gitaly/service/repository/archive_test.go @@ -191,7 +191,7 @@ func TestGetArchiveWithLfsSuccess(t *testing.T) { repo, _, cleanup := gittest.CloneRepoAtStorage(t, cfg.Storages[0], t.Name()) t.Cleanup(cleanup) - testhelper.ConfigureGitalyLfsSmudge(cfg.BinDir) + testhelper.ConfigureGitalyLfsSmudge(t, cfg.BinDir) // lfs-moar branch SHA sha := "46abbb087fcc0fd02c340f0f2f052bd2c7708da3" diff --git a/internal/testhelper/configure.go b/internal/testhelper/configure.go index d660d2c49..b2a647426 100644 --- a/internal/testhelper/configure.go +++ b/internal/testhelper/configure.go @@ -138,8 +138,8 @@ func ConfigureGitalyGit2GoBin(t testing.TB, cfg config.Cfg) { } // ConfigureGitalyLfsSmudge configures the gitaly-lfs-smudge command for tests -func ConfigureGitalyLfsSmudge(outputDir string) { - buildCommand(nil, outputDir, "gitaly-lfs-smudge") +func ConfigureGitalyLfsSmudge(t *testing.T, outputDir string) { + buildCommand(t, outputDir, "gitaly-lfs-smudge") } // ConfigureGitalyHooksBin builds gitaly-hooks command for tests for the cfg. diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index c5557c391..b075a1ebf 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -126,29 +126,13 @@ storages: // MustRunCommand runs a command with an optional standard input and returns the standard output, or fails. func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string) []byte { - if t != nil { - t.Helper() - } + t.Helper() - var cmd *exec.Cmd - if name == "git" { - if args[0] == "init" { - // Many tests depend on the fact "master" is the initial branch. - // To overcome the case when the user has set anything else in - // their git-config, override it to be "master". - args = append([]string{"-c", "init.defaultBranch=master"}, args...) - } - cmd = exec.Command(config.Config.Git.BinPath, args...) - cmd.Env = os.Environ() - cmd.Env = append(command.GitEnv, cmd.Env...) - cmd.Env = append(cmd.Env, - "GIT_AUTHOR_DATE=1572776879 +0100", - "GIT_COMMITTER_DATE=1572776879 +0100", - ) - } else { - cmd = exec.Command(name, args...) + if filepath.Base(name) == "git" { + require.Fail(t, "Please use gittest.Exec or gittest.ExecStream to run git commands.") } + cmd := exec.Command(name, args...) if stdin != nil { cmd.Stdin = stdin } @@ -156,15 +140,7 @@ func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string) output, err := cmd.Output() if err != nil { stderr := err.(*exec.ExitError).Stderr - if t == nil { - log.Print(name, args) - log.Printf("%s", stderr) - panic(err) - } else { - t.Log(name, args) - t.Logf("%s", stderr) - t.Fatal(err) - } + require.NoError(t, err, "%s %s: %s", name, args, stderr) } return output |