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:
authorSami Hiltunen <shiltunen@gitlab.com>2022-02-10 17:15:59 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-23 14:20:21 +0300
commit640e29c52158a503bcd65623fd9b52637f618410 (patch)
treed5a7e6490e718af3733cd214e788061cf427d5e4
parentfe5eccd6e55ccc8fbe985c6ad6e205eb02ce1284 (diff)
Use replica path in backup tests
Backup tests are accessing the repository on the file system. Doing so, they expect the repository to stored at the relative path. This is not the case when Praefect is rewriting relative paths. Fix this by using the returned path from the CreateRepository helper.
-rw-r--r--internal/backup/backup_test.go46
1 files changed, 22 insertions, 24 deletions
diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go
index 1486aa211..18f572a72 100644
--- a/internal/backup/backup_test.go
+++ b/internal/backup/backup_test.go
@@ -37,42 +37,42 @@ func TestManager_Create(t *testing.T) {
for _, tc := range []struct {
desc string
- setup func(t testing.TB) *gitalypb.Repository
+ setup func(t testing.TB) (*gitalypb.Repository, string)
createsBundle bool
createsCustomHooks bool
err error
}{
{
desc: "no hooks",
- setup: func(t testing.TB) *gitalypb.Repository {
- noHooksRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ setup: func(t testing.TB) (*gitalypb.Repository, string) {
+ noHooksRepo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: "no-hooks",
Seed: gittest.SeedGitLabTest,
})
- return noHooksRepo
+ return noHooksRepo, repoPath
},
createsBundle: true,
createsCustomHooks: false,
},
{
desc: "hooks",
- setup: func(t testing.TB) *gitalypb.Repository {
+ setup: func(t testing.TB) (*gitalypb.Repository, string) {
hooksRepo, hooksRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: "hooks",
Seed: gittest.SeedGitLabTest,
})
require.NoError(t, os.Mkdir(filepath.Join(hooksRepoPath, "custom_hooks"), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(hooksRepoPath, "custom_hooks/pre-commit.sample"), []byte("Some hooks"), os.ModePerm))
- return hooksRepo
+ return hooksRepo, hooksRepoPath
},
createsBundle: true,
createsCustomHooks: true,
},
{
desc: "empty repo",
- setup: func(t testing.TB) *gitalypb.Repository {
- emptyRepo, _ := gittest.CreateRepository(ctx, t, cfg)
- return emptyRepo
+ setup: func(t testing.TB) (*gitalypb.Repository, string) {
+ emptyRepo, repoPath := gittest.CreateRepository(ctx, t, cfg)
+ return emptyRepo, repoPath
},
createsBundle: false,
createsCustomHooks: false,
@@ -80,11 +80,11 @@ func TestManager_Create(t *testing.T) {
},
{
desc: "nonexistent repo",
- setup: func(t testing.TB) *gitalypb.Repository {
- emptyRepo, _ := gittest.CreateRepository(ctx, t, cfg)
+ setup: func(t testing.TB) (*gitalypb.Repository, string) {
+ emptyRepo, repoPath := gittest.CreateRepository(ctx, t, cfg)
nonexistentRepo := proto.Clone(emptyRepo).(*gitalypb.Repository)
nonexistentRepo.RelativePath = "nonexistent"
- return nonexistentRepo
+ return nonexistentRepo, repoPath
},
createsBundle: false,
createsCustomHooks: false,
@@ -92,8 +92,7 @@ func TestManager_Create(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- repo := tc.setup(t)
- repoPath := filepath.Join(cfg.Storages[0].Path, repo.RelativePath)
+ repo, repoPath := tc.setup(t)
path := testhelper.TempDir(t)
refsPath := filepath.Join(path, repo.RelativePath, backupID, "001.refs")
bundlePath := filepath.Join(path, repo.RelativePath, backupID, "001.bundle")
@@ -160,24 +159,24 @@ func TestManager_Create_incremental(t *testing.T) {
for _, tc := range []struct {
desc string
- setup func(t testing.TB, backupRoot string) *gitalypb.Repository
+ setup func(t testing.TB, backupRoot string) (*gitalypb.Repository, string)
expectedIncrement string
expectedErr error
}{
{
desc: "no previous backup",
- setup: func(t testing.TB, backupRoot string) *gitalypb.Repository {
- repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ setup: func(t testing.TB, backupRoot string) (*gitalypb.Repository, string) {
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: "repo",
Seed: gittest.SeedGitLabTest,
})
- return repo
+ return repo, repoPath
},
expectedIncrement: "001",
},
{
desc: "previous backup, no updates",
- setup: func(t testing.TB, backupRoot string) *gitalypb.Repository {
+ setup: func(t testing.TB, backupRoot string) (*gitalypb.Repository, string) {
repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: "repo",
Seed: gittest.SeedGitLabTest,
@@ -197,13 +196,13 @@ func TestManager_Create_incremental(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(backupRepoPath, "LATEST"), []byte(backupID), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(backupPath, "LATEST"), []byte("001"), os.ModePerm))
- return repo
+ return repo, repoPath
},
expectedErr: fmt.Errorf("manager: write bundle: %w", fmt.Errorf("*backup.FilesystemSink write: %w: no changes to bundle", ErrSkipped)),
},
{
desc: "previous backup, updates",
- setup: func(t testing.TB, backupRoot string) *gitalypb.Repository {
+ setup: func(t testing.TB, backupRoot string) (*gitalypb.Repository, string) {
repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: "repo",
Seed: gittest.SeedGitLabTest,
@@ -225,16 +224,15 @@ func TestManager_Create_incremental(t *testing.T) {
gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"))
- return repo
+ return repo, repoPath
},
expectedIncrement: "002",
},
} {
t.Run(tc.desc, func(t *testing.T) {
path := testhelper.TempDir(t)
- repo := tc.setup(t, path)
+ repo, repoPath := tc.setup(t, path)
- repoPath := filepath.Join(cfg.Storages[0].Path, repo.RelativePath)
refsPath := filepath.Join(path, repo.RelativePath, backupID, tc.expectedIncrement+".refs")
bundlePath := filepath.Join(path, repo.RelativePath, backupID, tc.expectedIncrement+".bundle")