diff options
author | James Liu <jliu@gitlab.com> | 2023-12-12 06:54:25 +0300 |
---|---|---|
committer | James Liu <jliu@gitlab.com> | 2024-01-15 05:40:54 +0300 |
commit | ada54fc25380ad5b6844f46df793a62075b4bb31 (patch) | |
tree | 64aaf7b2a38d7b10f424ca066b4e1a70d82cdac1 /internal/backup/backup_test.go | |
parent | 95bbcbcca4a2f344a171dba71f30071850f0fba6 (diff) |
backup: Add RemoveRepository to the strategy
Adds a new method to the Strategy interface used by regular and
server-side backups for performing repository backups and restores. This
new method removes a single repository from its storage, and will
eventually replace the existing RemoveAllRepositories method.
Diffstat (limited to 'internal/backup/backup_test.go')
-rw-r--r-- | internal/backup/backup_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index 14341ec6a..ca92ad546 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -65,6 +65,49 @@ Issue: https://gitlab.com/gitlab-org/gitaly/-/issues/5269`) require.NoError(t, err) } +func TestManager_RemoveRepository(t *testing.T) { + if testhelper.IsPraefectEnabled() { + t.Skip("local backup manager expects to operate on the local filesystem so cannot operate through praefect") + } + + t.Parallel() + + cfg := testcfg.Build(t) + cfg.SocketPath = testserver.RunGitalyServer(t, cfg, setup.RegisterAll) + + ctx := testhelper.Context(t) + + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) + gittest.WriteTag(t, cfg, repoPath, "v1.0.0", commitID.Revision()) + + pool := client.NewPool() + defer testhelper.MustClose(t, pool) + + backupRoot := testhelper.TempDir(t) + sink := backup.NewFilesystemSink(backupRoot) + defer testhelper.MustClose(t, sink) + + locator, err := backup.ResolveLocator("pointer", sink) + require.NoError(t, err) + + fsBackup := backup.NewManager(sink, locator, pool) + err = fsBackup.RemoveRepository(ctx, &backup.RemoveRepositoryRequest{ + Server: storage.ServerInfo{Address: cfg.SocketPath, Token: cfg.Auth.Token}, + Repo: repo, + }) + require.NoError(t, err) + require.NoDirExists(t, repoPath) + + // With an invalid repository + err = fsBackup.RemoveRepository(ctx, &backup.RemoveRepositoryRequest{ + Server: storage.ServerInfo{Address: cfg.SocketPath, Token: cfg.Auth.Token}, + Repo: &gitalypb.Repository{StorageName: "nonexistent", RelativePath: "nonexistent"}, + }) + + require.EqualError(t, err, "remove repo: remove: rpc error: code = InvalidArgument desc = storage name not found") +} + func TestManager_Create(t *testing.T) { t.Parallel() |