Add emergency repository unlock

This commit is contained in:
Mikei386
2026-06-21 13:59:10 +02:00
parent 84df215ad0
commit 92ba5ce05f
11 changed files with 68 additions and 9 deletions
+19
View File
@@ -343,6 +343,25 @@ func TestUnlockUsesSafeResticCommand(t *testing.T) {
}
}
func TestForceUnlockRemovesAllRepositoryLocks(t *testing.T) {
dir := t.TempDir()
argsPath := filepath.Join(dir, "args")
script := filepath.Join(dir, "restic")
body := fmt.Sprintf("#!/bin/sh\nprintf '%%s\\n' \"$@\" > '%s'\n", argsPath)
if err := os.WriteFile(script, []byte(body), 0700); err != nil {
t.Fatal(err)
}
runner := &Runner{Binary: script, RuntimeDir: dir, Secrets: fakeSecrets{"password": "secret"}}
repo := model.Repository{Type: model.RepositoryLocal, Location: "/repo", PasswordRef: "password"}
if err := runner.ForceUnlock(context.Background(), repo); err != nil {
t.Fatal(err)
}
args, _ := os.ReadFile(argsPath)
if !strings.Contains(string(args), "unlock\n--remove-all") {
t.Fatalf("force unlock did not use remove-all: %s", args)
}
}
func TestResticErrorExplainsExistingRepository(t *testing.T) {
err := resticError("Fatal: create repository failed: config file already exists", fmt.Errorf("exit status 1"))
if !strings.Contains(err.Error(), "already initialized") || !strings.Contains(err.Error(), "select Test") {