d02a093eeb
P2R-14. New store.LatestJobBySchedule query (per-schedule fired job). Schedules-tab handler computes next-fire from cron + last-fire from the jobs table per row. Schedules table grows two columns; dashboard host row prepends 'next 12h ago/from now' to the existing last-backup line when a single covering schedule is the run-now candidate. Embeds store.Schedule into scheduleRow so existing template field references keep working without bulk renames.
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// schedule_nextrun_test.go — pin the cron parser → next-run shape we
|
|
// rely on for the dashboard host row + schedules tab (P2R-14).
|
|
package http
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCronParserNext(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
expr string
|
|
from time.Time
|
|
want time.Time
|
|
}{
|
|
{
|
|
name: "daily at 03:00",
|
|
expr: "0 3 * * *",
|
|
from: time.Date(2026, 5, 4, 1, 0, 0, 0, time.UTC),
|
|
want: time.Date(2026, 5, 4, 3, 0, 0, 0, time.UTC),
|
|
},
|
|
{
|
|
name: "daily at 03:00 (after time of day → next day)",
|
|
expr: "0 3 * * *",
|
|
from: time.Date(2026, 5, 4, 5, 0, 0, 0, time.UTC),
|
|
want: time.Date(2026, 5, 5, 3, 0, 0, 0, time.UTC),
|
|
},
|
|
{
|
|
name: "every 15 minutes",
|
|
expr: "*/15 * * * *",
|
|
from: time.Date(2026, 5, 4, 1, 7, 0, 0, time.UTC),
|
|
want: time.Date(2026, 5, 4, 1, 15, 0, 0, time.UTC),
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
parsed, err := cronParser.Parse(c.expr)
|
|
if err != nil {
|
|
t.Fatalf("parse %q: %v", c.expr, err)
|
|
}
|
|
got := parsed.Next(c.from)
|
|
if !got.Equal(c.want) {
|
|
t.Fatalf("Next(%v) = %v, want %v", c.from, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|