Fix backup check notifications and workload recovery; release 2026.09.21.r001
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.casaderoll.de/michael/urbm/internal/notify"
|
||||
"git.casaderoll.de/michael/urbm/internal/platform"
|
||||
"git.casaderoll.de/michael/urbm/internal/queue"
|
||||
"git.casaderoll.de/michael/urbm/internal/restic"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -42,3 +51,41 @@ func TestNotificationMessageIncludesPruneSummary(t *testing.T) {
|
||||
t.Fatalf("message contains redundant prune completion details: %q", message)
|
||||
}
|
||||
}
|
||||
|
||||
type checkSecrets struct{}
|
||||
|
||||
func (checkSecrets) Get(string) (string, error) { return "test", nil }
|
||||
|
||||
func TestCheckSendsSuccessAndFailureNotifications(t *testing.T) {
|
||||
for _, code := range []int{0, 1} {
|
||||
t.Run(fmt.Sprint(code), func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
binary := filepath.Join(dir, "restic")
|
||||
if err := os.WriteFile(binary, []byte(fmt.Sprintf("#!/bin/sh\necho check-result >&2\nexit %d\n", code)), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var sent []string
|
||||
s := &Service{
|
||||
config: model.Config{Repositories: []model.Repository{{ID: "repo", Name: "test", Type: model.RepositoryLocal, Location: dir}}, Notifications: []model.NotificationTarget{{Type: "unraid", Enabled: true, Events: []string{"success", "failed"}}}},
|
||||
repositoryLocks: map[string]chan struct{}{},
|
||||
restic: &restic.Runner{Binary: binary, RuntimeDir: dir, Secrets: checkSecrets{}},
|
||||
mounts: &platform.MountManager{}, queue: queue.New(nil, nil), log: slog.Default(),
|
||||
notifier: ¬ify.Sender{RunCommand: func(_ context.Context, _ string, args ...string) error {
|
||||
sent = append(sent, strings.Join(args, " "))
|
||||
return nil
|
||||
}},
|
||||
}
|
||||
result := s.execute(context.Background(), model.Run{ID: "run", JobID: "repo", TaskType: "check"})
|
||||
want := "success"
|
||||
if code != 0 {
|
||||
want = "failed"
|
||||
}
|
||||
if result.Status != want || len(sent) != 1 {
|
||||
t.Fatalf("status=%s messages=%v", result.Status, sent)
|
||||
}
|
||||
if !strings.Contains(sent[0], "URBM") {
|
||||
t.Fatal(sent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user