diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-05-03 22:04:41 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-05-11 14:25:16 +0300 |
commit | 2eae6cb13ee022e0322211337d395d4fd7e22374 (patch) | |
tree | 29374dc9ca271243c4253464c32a2b4d9207ce8e | |
parent | 0d237bee58d2adaaa400a6df6be62e8ac40a4382 (diff) |
Replace MustRunCommand with gittest.Exec in upload_pack_test.go
To break dependency on the global config.Config variable the
git commands should be executed with gittest.Exec.
The functions require a config.Cfg to be passed as incoming parameter to
use proper git binary for the command execution. This change modifies
all related functions to pass through config.Cfg to the place of
the function replacement.
Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r-- | internal/gitaly/service/ssh/upload_pack_test.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go index a9b2012a2..60d46a3d3 100644 --- a/internal/gitaly/service/ssh/upload_pack_test.go +++ b/internal/gitaly/service/ssh/upload_pack_test.go @@ -73,7 +73,7 @@ func (cmd cloneCommand) execute(t *testing.T) error { return nil } -func (cmd cloneCommand) test(t *testing.T, repoPath string, localRepoPath string) (string, string, string, string) { +func (cmd cloneCommand) test(t *testing.T, cfg config.Cfg, repoPath string, localRepoPath string) (string, string, string, string) { t.Helper() defer os.RemoveAll(localRepoPath) @@ -81,11 +81,11 @@ func (cmd cloneCommand) test(t *testing.T, repoPath string, localRepoPath string err := cmd.execute(t) require.NoError(t, err) - remoteHead := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", "master")) - localHead := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", localRepoPath, "rev-parse", "master")) + remoteHead := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "master")) + localHead := text.ChompBytes(gittest.Exec(t, cfg, "-C", localRepoPath, "rev-parse", "master")) - remoteTags := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "tag")) - localTags := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", localRepoPath, "tag")) + remoteTags := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "tag")) + localTags := text.ChompBytes(gittest.Exec(t, cfg, "-C", localRepoPath, "tag")) return localHead, remoteHead, localTags, remoteTags } @@ -237,7 +237,7 @@ func TestUploadPackCloneSuccess(t *testing.T) { server: serverSocketPath, cfg: cfg, } - lHead, rHead, _, _ := cmd.test(t, repoPath, localRepoPath) + lHead, rHead, _, _ := cmd.test(t, cfg, repoPath, localRepoPath) require.Equal(t, lHead, rHead, "local and remote head not equal") metric, err := negotiationMetrics.GetMetricWithLabelValues("deepen") @@ -424,7 +424,7 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) { cfg: cfg, } - lHead, rHead, _, _ := cmd.test(t, repoPath, localRepoPath) + lHead, rHead, _, _ := cmd.test(t, cfg, repoPath, localRepoPath) require.Equal(t, lHead, rHead, "local and remote head not equal") envData := readProto() @@ -453,7 +453,7 @@ func TestUploadPackCloneHideTags(t *testing.T) { gitConfig: "transfer.hideRefs=refs/tags", cfg: cfg, } - _, _, lTags, rTags := cloneCmd.test(t, repoPath, localRepoPath) + _, _, lTags, rTags := cloneCmd.test(t, cfg, repoPath, localRepoPath) if lTags == rTags { t.Fatalf("local and remote tags are equal. clone failed: %q != %q", lTags, rTags) |