- planification crontab par stack (autoupdate.json), incompatible avec l'exclusion
- scheduler a la minute ; pull puis down + up -d seulement si une image a change (mode autoapply)
- API PUT .../targets/{t}/auto et GET /api/cron (apercu des prochaines executions)
- interface : option dans le detail, badge sarcelle, vue de suivi "Mises a jour auto"
- TZ dans docker-compose / .env.example (tzdata embarque)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm6UCYFyvNQNSF5i9Gy
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package fleet
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCronNext(t *testing.T) {
|
|
paris, err := time.LoadLocation("Europe/Paris")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
from := time.Date(2026, 11, 23, 10, 7, 30, 0, paris) // lundi
|
|
cases := []struct{ expr, want string }{
|
|
{"*/15 * * * *", "2026-11-23 10:15"},
|
|
{"30 4 * * *", "2026-11-24 04:30"},
|
|
{"@daily", "2026-11-24 00:00"},
|
|
{"@hourly", "2026-11-23 11:00"},
|
|
{"0 3 * * sun", "2026-11-29 03:00"},
|
|
{"0 3 * * 7", "2026-11-29 03:00"},
|
|
{"0 3 * * 1-5", "2026-11-24 03:00"},
|
|
{"0 2 1 * *", "2026-12-01 02:00"},
|
|
{"0 0 1 jan *", "2027-01-01 00:00"},
|
|
{"0 0 13 * 5", "2026-11-27 00:00"}, // jour 13 OU vendredi
|
|
{"5,35 */6 * * *", "2026-11-23 12:05"},
|
|
{"0 0 30 2 *", ""},
|
|
}
|
|
for _, c := range cases {
|
|
cr, err := ParseCron(c.expr)
|
|
if err != nil {
|
|
t.Fatalf("%s : %v", c.expr, err)
|
|
}
|
|
got := ""
|
|
if n := cr.Next(from); !n.IsZero() {
|
|
got = n.Format("2006-01-02 15:04")
|
|
if !cr.Match(n) {
|
|
t.Errorf("%s : Next %s ne correspond pas", c.expr, got)
|
|
}
|
|
}
|
|
if got != c.want {
|
|
t.Errorf("%s : %s, attendu %s", c.expr, got, c.want)
|
|
}
|
|
}
|
|
// Passage a l'heure d'ete : 02:30 n'existe pas le 29 mars 2026.
|
|
cr, _ := ParseCron("30 * * * *")
|
|
n := cr.Next(time.Date(2026, 3, 29, 1, 45, 0, 0, paris))
|
|
if n.Format("15:04") != "03:30" {
|
|
t.Errorf("heure d'ete : %s", n)
|
|
}
|
|
}
|
|
|
|
func TestCronInvalid(t *testing.T) {
|
|
for _, e := range []string{"", "* * * *", "60 * * * *", "* 24 * * *", "* * 0 * *", "* * * 13 *", "* * * * 8", "*/0 * * * *", "5-1 * * * *", "a * * * *", "* * * * * *"} {
|
|
if _, err := ParseCron(e); err == nil {
|
|
t.Errorf("%q accepte", e)
|
|
}
|
|
}
|
|
}
|