Add emergency repository unlock
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user