diff options
author | James Fargher <jfargher@gitlab.com> | 2024-01-24 02:47:14 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2024-01-24 02:55:08 +0300 |
commit | f5b538cc73aeb09619b69ec65ec0d2644030e8ba (patch) | |
tree | 4005ca48f326acbc9438dd6c1d1d78359abaf21d | |
parent | 7d1705353eba259b3c52be7c7cae5f120b953a23 (diff) |
gitalybackup: Convert tests to use manifestsrefactor_restore_tests
Previously these tests relied on falling back to the legacy locator.
Instead rewrite the tests to use manifests.
Now that they run on manifests these tests can also be run in SHA256
mode.
-rw-r--r-- | internal/cli/gitalybackup/restore_test.go | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/internal/cli/gitalybackup/restore_test.go b/internal/cli/gitalybackup/restore_test.go index 4b1eee9aa..e5ba37c14 100644 --- a/internal/cli/gitalybackup/restore_test.go +++ b/internal/cli/gitalybackup/restore_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "os" "path/filepath" "runtime" "strconv" @@ -16,7 +15,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service/setup" - "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testserver" @@ -24,8 +22,6 @@ import ( ) func TestRestoreSubcommand(t *testing.T) { - gittest.SkipWithSHA256(t) - ctx := testhelper.Context(t) cfg := testcfg.Build(t) @@ -42,11 +38,10 @@ func TestRestoreSubcommand(t *testing.T) { // The backupDir contains the artifacts that would've been created as part of a backup. backupDir := testhelper.TempDir(t) - existingRepoBundlePath := filepath.Join(backupDir, existingRepo.RelativePath+".bundle") - existingRepoRefPath := filepath.Join(backupDir, existingRepo.RelativePath+".refs") - - gittest.Exec(t, cfg, "-C", existRepoPath, "bundle", "create", existingRepoBundlePath, "--all") - require.NoError(t, os.WriteFile(existingRepoRefPath, gittest.Exec(t, cfg, "-C", existRepoPath, "show-ref"), perm.SharedFile)) + testhelper.WriteFiles(t, backupDir, map[string]any{ + filepath.Join(existingRepo.RelativePath + ".bundle"): gittest.Exec(t, cfg, "-C", existRepoPath, "bundle", "create", "-", "--all"), + filepath.Join(existingRepo.RelativePath + ".refs"): gittest.Exec(t, cfg, "-C", existRepoPath, "show-ref"), + }) // These repos are the ones being restored, and should exist after the restore. var repos []*gitalypb.Repository @@ -56,10 +51,17 @@ func TestRestoreSubcommand(t *testing.T) { Storage: cfg.Storages[0], }) - repoBundlePath := filepath.Join(backupDir, repo.RelativePath+".bundle") - testhelper.CopyFile(t, existingRepoBundlePath, repoBundlePath) - repoRefPath := filepath.Join(backupDir, repo.RelativePath+".refs") - testhelper.CopyFile(t, existingRepoRefPath, repoRefPath) + testhelper.WriteFiles(t, backupDir, map[string]any{ + filepath.Join("manifests", repo.StorageName, repo.RelativePath, "+latest.toml"): fmt.Sprintf(` +object_format = '%[1]s' + +[[steps]] +bundle_path = '%[2]s.bundle' +ref_path = '%[2]s.refs' +custom_hooks_path = '%[2]s/custom_hooks.tar' +`, gittest.DefaultObjectHash.Format, existingRepo.RelativePath), + }) + repos = append(repos, repo) } @@ -105,7 +107,7 @@ func TestRestoreSubcommand(t *testing.T) { // Ensure the repos were restored correctly. for _, repo := range repos { repoPath := filepath.Join(cfg.Storages[0].Path, gittest.GetReplicaPath(t, ctx, cfg, repo)) - bundlePath := filepath.Join(backupDir, repo.RelativePath+".bundle") + bundlePath := filepath.Join(backupDir, existingRepo.RelativePath+".bundle") output := gittest.Exec(t, cfg, "-C", repoPath, "bundle", "verify", bundlePath) require.Contains(t, string(output), "The bundle records a complete history") @@ -113,8 +115,6 @@ func TestRestoreSubcommand(t *testing.T) { } func TestRestoreSubcommand_serverSide(t *testing.T) { - gittest.SkipWithSHA256(t) - ctx := testhelper.Context(t) backupDir := testhelper.TempDir(t) @@ -137,11 +137,10 @@ func TestRestoreSubcommand_serverSide(t *testing.T) { }) gittest.WriteCommit(t, cfg, existRepoPath, gittest.WithBranch(git.DefaultBranch)) - existingRepoBundlePath := filepath.Join(backupDir, existingRepo.RelativePath+".bundle") - existingRepoRefPath := filepath.Join(backupDir, existingRepo.RelativePath+".refs") - - gittest.Exec(t, cfg, "-C", existRepoPath, "bundle", "create", existingRepoBundlePath, "--all") - require.NoError(t, os.WriteFile(existingRepoRefPath, gittest.Exec(t, cfg, "-C", existRepoPath, "show-ref"), perm.SharedFile)) + testhelper.WriteFiles(t, backupDir, map[string]any{ + filepath.Join(existingRepo.RelativePath + ".bundle"): gittest.Exec(t, cfg, "-C", existRepoPath, "bundle", "create", "-", "--all"), + filepath.Join(existingRepo.RelativePath + ".refs"): gittest.Exec(t, cfg, "-C", existRepoPath, "show-ref"), + }) var repos []*gitalypb.Repository for i := 0; i < 2; i++ { @@ -150,10 +149,17 @@ func TestRestoreSubcommand_serverSide(t *testing.T) { Storage: cfg.Storages[0], }) - repoBundlePath := filepath.Join(backupDir, repo.RelativePath+".bundle") - testhelper.CopyFile(t, existingRepoBundlePath, repoBundlePath) - repoRefPath := filepath.Join(backupDir, repo.RelativePath+".refs") - testhelper.CopyFile(t, existingRepoRefPath, repoRefPath) + testhelper.WriteFiles(t, backupDir, map[string]any{ + filepath.Join("manifests", repo.StorageName, repo.RelativePath, "+latest.toml"): fmt.Sprintf(` +object_format = '%[1]s' + +[[steps]] +bundle_path = '%[2]s.bundle' +ref_path = '%[2]s.refs' +custom_hooks_path = '%[2]s/custom_hooks.tar' +`, gittest.DefaultObjectHash.Format, existingRepo.RelativePath), + }) + repos = append(repos, repo) } @@ -198,7 +204,7 @@ func TestRestoreSubcommand_serverSide(t *testing.T) { for _, repo := range repos { repoPath := filepath.Join(cfg.Storages[0].Path, gittest.GetReplicaPath(t, ctx, cfg, repo)) - bundlePath := filepath.Join(backupDir, repo.RelativePath+".bundle") + bundlePath := filepath.Join(backupDir, existingRepo.RelativePath+".bundle") output := gittest.Exec(t, cfg, "-C", repoPath, "bundle", "verify", bundlePath) require.Contains(t, string(output), "The bundle records a complete history") |