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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-21 12:41:39 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-21 15:16:12 +0300
commit0ca4c3d402632a75e07d2e32b89dd68e2534c902 (patch)
treec5c18a1dc8eb453c3ebf25e26ef8dc45057f6e07
parent48bd1b772c2fe1c648147304b577e886097012be (diff)
localrepo: Convert tests for size with excluded refs to be table-driven
Convert the tests for calculating the repository size for a repository while excluding a subset of references to be table-driven instead of using a standalone test. This will our increase test coverage when we start verifying command line parameters passed to git-rev-list(1).
-rw-r--r--internal/git/localrepo/repo_test.go88
1 files changed, 50 insertions, 38 deletions
diff --git a/internal/git/localrepo/repo_test.go b/internal/git/localrepo/repo_test.go
index 04e486403..61ee54b9b 100644
--- a/internal/git/localrepo/repo_test.go
+++ b/internal/git/localrepo/repo_test.go
@@ -1,7 +1,6 @@
package localrepo
import (
- "bytes"
"context"
"os"
"path/filepath"
@@ -52,6 +51,7 @@ func TestSize(t *testing.T) {
testCases := []struct {
desc string
setup func(t *testing.T) *gitalypb.Repository
+ opts []RepoSizeOption
expectedSize int64
}{
{
@@ -147,6 +147,54 @@ func TestSize(t *testing.T) {
},
expectedSize: 398,
},
+ {
+ desc: "excluded single ref",
+ setup: func(t *testing.T) *gitalypb.Repository {
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+
+ gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "1kbblob", Mode: "100644", Content: strings.Repeat("a", 1000)},
+ ),
+ gittest.WithBranch("exclude-me"),
+ )
+
+ gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "1kbblob", Mode: "100644", Content: strings.Repeat("x", 2000)},
+ ),
+ gittest.WithBranch("include-me"),
+ )
+
+ return repoProto
+ },
+ opts: []RepoSizeOption{
+ WithExcludeRefs("refs/heads/exclude-me"),
+ },
+ expectedSize: 217,
+ },
+ {
+ desc: "excluded everything",
+ setup: func(t *testing.T) *gitalypb.Repository {
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+
+ gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "1kbblob", Mode: "100644", Content: strings.Repeat("a", 1000)},
+ ),
+ gittest.WithBranch("exclude-me"),
+ )
+
+ return repoProto
+ },
+ opts: []RepoSizeOption{
+ WithExcludeRefs("refs/heads/*"),
+ },
+ expectedSize: 0,
+ },
}
for _, tc := range testCases {
@@ -155,49 +203,13 @@ func TestSize(t *testing.T) {
repo := New(config.NewLocator(cfg), gitCmdFactory, catfileCache, repoProto)
ctx := testhelper.Context(t)
- size, err := repo.Size(ctx)
+ size, err := repo.Size(ctx, tc.opts...)
require.NoError(t, err)
assert.Equal(t, tc.expectedSize, size)
})
}
}
-func TestSize_excludeRefs(t *testing.T) {
- cfg := testcfg.Build(t)
- gitCmdFactory := gittest.NewCommandFactory(t, cfg)
- catfileCache := catfile.NewCache(cfg)
- t.Cleanup(catfileCache.Stop)
-
- pbRepo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- blob := bytes.Repeat([]byte("a"), 1000)
- blobOID := gittest.WriteBlob(t, cfg, repoPath, blob)
- treeOID := gittest.WriteTree(t, cfg, repoPath, []gittest.TreeEntry{
- {
- OID: blobOID,
- Mode: "100644",
- Path: "1kbblob",
- },
- })
- commitOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTree(treeOID))
-
- repo := New(config.NewLocator(cfg), gitCmdFactory, catfileCache, pbRepo)
-
- ctx := testhelper.Context(t)
- sizeBeforeKeepAround, err := repo.Size(ctx)
- require.NoError(t, err)
-
- gittest.WriteRef(t, cfg, repoPath, git.ReferenceName("refs/keep-around/keep1"), commitOID)
-
- sizeWithKeepAround, err := repo.Size(ctx)
- require.NoError(t, err)
- assert.Less(t, sizeBeforeKeepAround, sizeWithKeepAround)
-
- sizeWithoutKeepAround, err := repo.Size(ctx, WithExcludeRefs("refs/keep-around/*"))
- require.NoError(t, err)
-
- assert.Equal(t, sizeBeforeKeepAround, sizeWithoutKeepAround)
-}
-
func TestSize_excludeAlternates(t *testing.T) {
cfg := testcfg.Build(t)
gitCmdFactory := gittest.NewCommandFactory(t, cfg)