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-11-04 15:56:59 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-11-07 10:22:03 +0300
commit9300ba7b552205dabf3b5fd720dc7af33ad8049c (patch)
treee7b3d0521fd9ef7dc28e2187f24b29573c9a72ef
parent0832a1b50096d50832ef33bdc5f0500d9ddea798 (diff)
stats: Refactor object info logging tests to not use seed repos
Same as the preceding commit, refactor tests for `stats.LogObjectInfo()` to not use seeded repositories.
-rw-r--r--internal/git/stats/objects_info_test.go74
1 files changed, 43 insertions, 31 deletions
diff --git a/internal/git/stats/objects_info_test.go b/internal/git/stats/objects_info_test.go
index c77c61c61..da7743a4d 100644
--- a/internal/git/stats/objects_info_test.go
+++ b/internal/git/stats/objects_info_test.go
@@ -5,7 +5,6 @@ package stats
import (
"os"
"path/filepath"
- "strings"
"testing"
"time"
@@ -79,17 +78,14 @@ func TestRepositoryProfile(t *testing.T) {
}
func TestLogObjectInfo(t *testing.T) {
+ t.Parallel()
+
ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
- repo1, repoPath1 := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
- })
- repo2, repoPath2 := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
- })
+ locator := config.NewLocator(cfg)
+ storagePath, err := locator.GetStorageByName(cfg.Storages[0].Name)
+ require.NoError(t, err)
requireObjectsInfo := func(entries []*logrus.Entry) ObjectsInfo {
for _, entry := range entries {
@@ -106,42 +102,58 @@ func TestLogObjectInfo(t *testing.T) {
}
t.Run("shared repo with multiple alternates", func(t *testing.T) {
- locator := config.NewLocator(cfg)
- storagePath, err := locator.GetStorageByName(repo1.GetStorageName())
- require.NoError(t, err)
+ t.Parallel()
- tmpDir, err := os.MkdirTemp(storagePath, "")
- require.NoError(t, err)
- defer func() { require.NoError(t, os.RemoveAll(tmpDir)) }()
+ logger, hook := test.NewNullLogger()
+ ctx := ctxlogrus.ToContext(ctx, logger.WithField("test", "logging"))
- // clone existing local repo with two alternates
- gittest.Exec(t, cfg, "clone", "--shared", repoPath1, "--reference", repoPath1, "--reference", repoPath2, tmpDir)
+ _, repoPath1 := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ })
+ gittest.WriteCommit(t, cfg, repoPath1, gittest.WithMessage("repo1"), gittest.WithBranch("main"))
- logger, hook := test.NewNullLogger()
- testCtx := ctxlogrus.ToContext(ctx, logger.WithField("test", "logging"))
+ _, repoPath2 := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ })
+ gittest.WriteCommit(t, cfg, repoPath2, gittest.WithMessage("repo2"), gittest.WithBranch("main"))
+
+ // clone existing local repo with two alternates
+ targetRepoName := gittest.NewRepositoryName(t, true)
+ targetRepoPath := filepath.Join(storagePath, targetRepoName)
+ gittest.Exec(t, cfg, "clone", "--bare", "--shared", repoPath1, "--reference", repoPath1, "--reference", repoPath2, targetRepoPath)
- LogObjectsInfo(testCtx, localrepo.NewTestRepo(t, cfg, &gitalypb.Repository{
- StorageName: repo1.StorageName,
- RelativePath: filepath.Join(strings.TrimPrefix(tmpDir, storagePath), ".git"),
+ LogObjectsInfo(ctx, localrepo.NewTestRepo(t, cfg, &gitalypb.Repository{
+ StorageName: cfg.Storages[0].Name,
+ RelativePath: targetRepoName,
}))
objectsInfo := requireObjectsInfo(hook.AllEntries())
- require.Equal(t, []string{repoPath1 + "/objects", repoPath2 + "/objects"}, objectsInfo.Alternates)
+ require.Equal(t, ObjectsInfo{
+ Alternates: []string{
+ filepath.Join(repoPath1, "/objects"),
+ filepath.Join(repoPath2, "/objects"),
+ },
+ }, objectsInfo)
})
t.Run("repo without alternates", func(t *testing.T) {
+ t.Parallel()
+
logger, hook := test.NewNullLogger()
- testCtx := ctxlogrus.ToContext(ctx, logger.WithField("test", "logging"))
+ ctx := ctxlogrus.ToContext(ctx, logger.WithField("test", "logging"))
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ })
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
- LogObjectsInfo(testCtx, localrepo.NewTestRepo(t, cfg, repo2))
+ LogObjectsInfo(ctx, localrepo.NewTestRepo(t, cfg, repo))
objectsInfo := requireObjectsInfo(hook.AllEntries())
- require.NotZero(t, objectsInfo.LooseObjects)
- require.NotZero(t, objectsInfo.LooseObjectsSize)
- require.NotZero(t, objectsInfo.PackedObjects)
- require.NotZero(t, objectsInfo.Packfiles)
- require.NotZero(t, objectsInfo.PackfilesSize)
- require.Nil(t, objectsInfo.Alternates)
+ require.Equal(t, ObjectsInfo{
+ LooseObjects: 2,
+ LooseObjectsSize: 8,
+ }, objectsInfo)
})
}