Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2021-05-11 17:12:14 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-05-11 18:32:09 +0300
commitc0f88d78711d70943c937323d404063b6cb854dc (patch)
tree4435a11aa565ea4be444f5afd3f51822254584ba
parent3d0cf4bff22911f49b0176d1136499fc6d700fd6 (diff)
MustRunCommand should not be used for git commands execution
MustRunCommand should not be used to run git commands as there are special functions for it in the gittest package. The function marked as a test helper and now requires testing.TB to be non-nil value. The failure message also was a bit refactored.
-rw-r--r--internal/testhelper/testhelper.go34
1 files changed, 5 insertions, 29 deletions
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