Initial Backupper Unraid plugin

This commit is contained in:
Mikei386
2026-06-13 22:07:31 +02:00
commit 5352a9da22
39 changed files with 3167 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package scheduler
import (
"testing"
"time"
)
func TestCronMatchesAndNext(t *testing.T) {
expr, err := Parse("*/15 2 * * 1-5")
if err != nil {
t.Fatal(err)
}
monday := time.Date(2026, 6, 15, 2, 30, 0, 0, time.UTC)
if !expr.Matches(monday) {
t.Fatal("expected expression to match")
}
next := expr.Next(time.Date(2026, 6, 15, 2, 31, 0, 0, time.UTC))
want := time.Date(2026, 6, 15, 2, 45, 0, 0, time.UTC)
if !next.Equal(want) {
t.Fatalf("next = %v, want %v", next, want)
}
}
func TestCronRejectsInvalid(t *testing.T) {
for _, value := range []string{"", "* * * *", "61 * * * *", "*/0 * * * *"} {
if _, err := Parse(value); err == nil {
t.Fatalf("accepted invalid cron %q", value)
}
}
}
func TestPreviousWithinCatchUpWindow(t *testing.T) {
expr, err := Parse("0 2 * * *")
if err != nil {
t.Fatal(err)
}
now := time.Date(2026, 6, 13, 8, 30, 0, 0, time.UTC)
want := time.Date(2026, 6, 13, 2, 0, 0, 0, time.UTC)
if got := previous(expr, now, 24*time.Hour); !got.Equal(want) {
t.Fatalf("previous = %v, want %v", got, want)
}
if got := previous(expr, now, 2*time.Hour); !got.IsZero() {
t.Fatalf("unexpected catch-up match %v", got)
}
}