diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-04-30 11:03:57 +0300 |
---|---|---|
committer | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-05-11 14:59:46 +0300 |
commit | 1fb9d236ff601efcf483ba2cbbca69b30bcfda3d (patch) | |
tree | fdd5c144a3147c39c55edd8e42fc00b174bad6e1 | |
parent | 770193118b3ea204d82a2729c6a66fdd75dfec46 (diff) |
Replace MustRunCommand with gittest.Exec|ExecStream in objectpool
The replacement is done to break dependency on the global
config.Config variable.
Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r-- | internal/git/objectpool/fetch_test.go | 23 | ||||
-rw-r--r-- | internal/git/objectpool/link_test.go | 12 | ||||
-rw-r--r-- | internal/git/objectpool/pool_test.go | 8 |
3 files changed, 22 insertions, 21 deletions
diff --git a/internal/git/objectpool/fetch_test.go b/internal/git/objectpool/fetch_test.go index c8f670239..d56bb65f4 100644 --- a/internal/git/objectpool/fetch_test.go +++ b/internal/git/objectpool/fetch_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) @@ -56,9 +57,9 @@ func TestFetchFromOriginDangling(t *testing.T) { // `git tag` automatically creates a ref, so our new tag is not dangling. // Deleting the ref should fix that. - testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "update-ref", "-d", "refs/tags/"+newTagName) + gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "update-ref", "-d", "refs/tags/"+newTagName) - fsckBefore := testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "fsck", "--connectivity-only", "--dangling") + fsckBefore := gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "fsck", "--connectivity-only", "--dangling") fsckBeforeLines := strings.Split(string(fsckBefore), "\n") for _, l := range []string{ @@ -74,7 +75,7 @@ func TestFetchFromOriginDangling(t *testing.T) { // non-dangling objects. require.NoError(t, pool.FetchFromOrigin(ctx, testRepo), "second fetch") - refsAfter := testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "for-each-ref", "--format=%(refname) %(objectname)") + refsAfter := gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "for-each-ref", "--format=%(refname) %(objectname)") refsAfterLines := strings.Split(string(refsAfter), "\n") for _, id := range []string{newBlob.String(), newTree.String(), newCommit.String(), newTag} { require.Contains(t, refsAfterLines, fmt.Sprintf("refs/dangling/%s %s", id, id)) @@ -122,7 +123,7 @@ func TestFetchFromOriginDeltaIslands(t *testing.T) { } // Make sure the old packfile, with bad delta chains, is deleted from the source repo - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "repack", "-ald") + gittest.Exec(t, pool.cfg, "-C", testRepoPath, "repack", "-ald") return nil }) @@ -170,8 +171,8 @@ func TestFetchFromOriginRefUpdates(t *testing.T) { } for ref, oid := range oldRefs { - require.Equal(t, oid, resolveRef(t, testRepoPath, "refs/"+ref), "look up %q in source", ref) - require.Equal(t, oid, resolveRef(t, poolPath, "refs/remotes/origin/"+ref), "look up %q in pool", ref) + require.Equal(t, oid, resolveRef(t, pool.cfg, testRepoPath, "refs/"+ref), "look up %q in source", ref) + require.Equal(t, oid, resolveRef(t, pool.cfg, poolPath, "refs/remotes/origin/"+ref), "look up %q in pool", ref) } newRefs := map[string]string{ @@ -184,21 +185,21 @@ func TestFetchFromOriginRefUpdates(t *testing.T) { } for ref, oid := range newRefs { - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "update-ref", "refs/"+ref, oid) - require.Equal(t, oid, resolveRef(t, testRepoPath, "refs/"+ref), "look up %q in source after update", ref) + gittest.Exec(t, pool.cfg, "-C", testRepoPath, "update-ref", "refs/"+ref, oid) + require.Equal(t, oid, resolveRef(t, pool.cfg, testRepoPath, "refs/"+ref), "look up %q in source after update", ref) } require.NoError(t, pool.FetchFromOrigin(ctx, testRepo), "update pool") for ref, oid := range newRefs { - require.Equal(t, oid, resolveRef(t, poolPath, "refs/remotes/origin/"+ref), "look up %q in pool after update", ref) + require.Equal(t, oid, resolveRef(t, pool.cfg, poolPath, "refs/remotes/origin/"+ref), "look up %q in pool after update", ref) } looseRefs := testhelper.MustRunCommand(t, nil, "find", filepath.Join(poolPath, "refs"), "-type", "f") require.Equal(t, "", string(looseRefs), "there should be no loose refs after the fetch") } -func resolveRef(t *testing.T, repo string, ref string) string { - out := testhelper.MustRunCommand(t, nil, "git", "-C", repo, "rev-parse", ref) +func resolveRef(t *testing.T, cfg config.Cfg, repo string, ref string) string { + out := gittest.Exec(t, cfg, "-C", repo, "rev-parse", ref) return text.ChompBytes(out) } diff --git a/internal/git/objectpool/link_test.go b/internal/git/objectpool/link_test.go index 7157df5ee..48da07490 100644 --- a/internal/git/objectpool/link_test.go +++ b/internal/git/objectpool/link_test.go @@ -55,24 +55,24 @@ func TestLinkRemoveBitmap(t *testing.T) { testRepoPath := filepath.Join(pool.cfg.Storages[0].Path, testRepo.RelativePath) poolPath := pool.FullPath() - testhelper.MustRunCommand(t, nil, "git", "-C", poolPath, "fetch", testRepoPath, "+refs/*:refs/*") + gittest.Exec(t, pool.cfg, "-C", poolPath, "fetch", testRepoPath, "+refs/*:refs/*") - testhelper.MustRunCommand(t, nil, "git", "-C", poolPath, "repack", "-adb") + gittest.Exec(t, pool.cfg, "-C", poolPath, "repack", "-adb") require.Len(t, listBitmaps(t, pool.FullPath()), 1, "pool bitmaps before") - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "repack", "-adb") + gittest.Exec(t, pool.cfg, "-C", testRepoPath, "repack", "-adb") require.Len(t, listBitmaps(t, testRepoPath), 1, "member bitmaps before") - refsBefore := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref") + refsBefore := gittest.Exec(t, pool.cfg, "-C", testRepoPath, "for-each-ref") require.NoError(t, pool.Link(ctx, testRepo)) require.Len(t, listBitmaps(t, pool.FullPath()), 1, "pool bitmaps after") require.Len(t, listBitmaps(t, testRepoPath), 0, "member bitmaps after") - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "fsck") + gittest.Exec(t, pool.cfg, "-C", testRepoPath, "fsck") - refsAfter := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref") + refsAfter := gittest.Exec(t, pool.cfg, "-C", testRepoPath, "for-each-ref") require.Equal(t, refsBefore, refsAfter, "compare member refs before/after link") } diff --git a/internal/git/objectpool/pool_test.go b/internal/git/objectpool/pool_test.go index 85c93e824..f62fb255d 100644 --- a/internal/git/objectpool/pool_test.go +++ b/internal/git/objectpool/pool_test.go @@ -98,7 +98,7 @@ func TestCreate(t *testing.T) { testRepoPath := filepath.Join(pool.cfg.Storages[0].Path, testRepo.RelativePath) - masterSha := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "show-ref", "master") + masterSha := gittest.Exec(t, pool.cfg, "-C", testRepoPath, "show-ref", "master") err := pool.Create(ctx, testRepo) require.NoError(t, err) @@ -113,15 +113,15 @@ func TestCreate(t *testing.T) { assert.True(t, os.IsNotExist(err)) // origin is set - out := testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "remote", "get-url", "origin") + out := gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "remote", "get-url", "origin") assert.Equal(t, testRepoPath, strings.TrimRight(string(out), "\n")) // refs exist - out = testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "show-ref", "refs/heads/master") + out = gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "show-ref", "refs/heads/master") assert.Equal(t, masterSha, out) // No problems - out = testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "cat-file", "-s", "55bc176024cfa3baaceb71db584c7e5df900ea65") + out = gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "cat-file", "-s", "55bc176024cfa3baaceb71db584c7e5df900ea65") assert.Equal(t, "282\n", string(out)) } |