From cf439642cae08dd4dab6a88bd026e8dedbff12d1 Mon Sep 17 00:00:00 2001 From: Pavlo Strokov Date: Tue, 27 Apr 2021 19:40:57 +0300 Subject: Replace MustRunCommand with Exec in RemoteExists Usages of the MustRunCommand replaced with Exec in order to break dependency on the global config.Config variable. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699 --- internal/git/gittest/remote.go | 6 +++--- internal/git/objectpool/link_test.go | 8 ++++---- internal/gitaly/service/objectpool/link_test.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/git/gittest/remote.go b/internal/git/gittest/remote.go index e4bbd4f9c..6b82665d7 100644 --- a/internal/git/gittest/remote.go +++ b/internal/git/gittest/remote.go @@ -4,16 +4,16 @@ import ( "strings" "testing" - "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" ) // RemoteExists tests if the repository at repoPath has a Git remote named remoteName. -func RemoteExists(t testing.TB, repoPath string, remoteName string) bool { +func RemoteExists(t testing.TB, cfg config.Cfg, repoPath string, remoteName string) bool { if remoteName == "" { t.Fatal("empty remote name") } - remotes := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "remote") + remotes := Exec(t, cfg, "-C", repoPath, "remote") for _, r := range strings.Split(string(remotes), "\n") { if r == remoteName { return true diff --git a/internal/git/objectpool/link_test.go b/internal/git/objectpool/link_test.go index faa8dd1f7..7157df5ee 100644 --- a/internal/git/objectpool/link_test.go +++ b/internal/git/objectpool/link_test.go @@ -42,7 +42,7 @@ func TestLink(t *testing.T) { require.Equal(t, content, newContent) - require.False(t, gittest.RemoteExists(t, pool.FullPath(), testRepo.GetGlRepository()), "pool remotes should not include %v", testRepo) + require.False(t, gittest.RemoteExists(t, pool.cfg, pool.FullPath(), testRepo.GetGlRepository()), "pool remotes should not include %v", testRepo) } func TestLinkRemoveBitmap(t *testing.T) { @@ -101,10 +101,10 @@ func TestUnlink(t *testing.T) { require.NoError(t, pool.Create(ctx, testRepo), "create pool") require.NoError(t, pool.Link(ctx, testRepo), "link test repo to pool") - require.False(t, gittest.RemoteExists(t, pool.FullPath(), testRepo.GetGlRepository()), "pool remotes should include %v", testRepo) + require.False(t, gittest.RemoteExists(t, pool.cfg, pool.FullPath(), testRepo.GetGlRepository()), "pool remotes should include %v", testRepo) require.NoError(t, pool.Unlink(ctx, testRepo), "unlink repo") - require.False(t, gittest.RemoteExists(t, pool.FullPath(), testRepo.GetGlRepository()), "pool remotes should no longer include %v", testRepo) + require.False(t, gittest.RemoteExists(t, pool.cfg, pool.FullPath(), testRepo.GetGlRepository()), "pool remotes should no longer include %v", testRepo) } func TestLinkAbsoluteLinkExists(t *testing.T) { @@ -137,5 +137,5 @@ func TestLinkAbsoluteLinkExists(t *testing.T) { testRepoObjectsPath := filepath.Join(testRepoPath, "objects") require.Equal(t, fullPath, filepath.Join(testRepoObjectsPath, string(content)), "the content of the alternates file should be the relative version of the absolute pat") - require.True(t, gittest.RemoteExists(t, pool.FullPath(), "origin"), "pool remotes should include %v", testRepo) + require.True(t, gittest.RemoteExists(t, pool.cfg, pool.FullPath(), "origin"), "pool remotes should include %v", testRepo) } diff --git a/internal/gitaly/service/objectpool/link_test.go b/internal/gitaly/service/objectpool/link_test.go index 2ca1dfd36..2b0576958 100644 --- a/internal/gitaly/service/objectpool/link_test.go +++ b/internal/gitaly/service/objectpool/link_test.go @@ -201,8 +201,8 @@ func TestUnlink(t *testing.T) { require.NoError(t, pool2.Remove(ctx)) }() - require.False(t, gittest.RemoteExists(t, pool.FullPath(), repo.GlRepository), "sanity check: remote exists in pool") - require.False(t, gittest.RemoteExists(t, pool.FullPath(), deletedRepo.GlRepository), "sanity check: remote exists in pool") + require.False(t, gittest.RemoteExists(t, cfg, pool.FullPath(), repo.GlRepository), "sanity check: remote exists in pool") + require.False(t, gittest.RemoteExists(t, cfg, pool.FullPath(), deletedRepo.GlRepository), "sanity check: remote exists in pool") testCases := []struct { desc string @@ -276,7 +276,7 @@ func TestUnlink(t *testing.T) { require.NoError(t, err, "call UnlinkRepositoryFromObjectPool") remoteName := tc.req.Repository.GlRepository - require.False(t, gittest.RemoteExists(t, pool.FullPath(), remoteName), "remote should no longer exist in pool") + require.False(t, gittest.RemoteExists(t, cfg, pool.FullPath(), remoteName), "remote should no longer exist in pool") }) } } -- cgit v1.2.3