Files
geo/server/internal/tenant/app/schedule_task_policy_test.go
T

63 lines
2.2 KiB
Go
Raw Normal View History

package app
import (
"testing"
sharedschedule "github.com/geo-platform/tenant-api/internal/shared/schedule"
)
func TestNormalizeSchedulePlanFixedTimeBuildsCronFromSelectedDays(t *testing.T) {
plan, err := normalizeSchedulePlan(ScheduleTaskRequest{
ScheduleKind: scheduleKindWeekly,
ScheduleDays: []string{"mon", "wed", "fri"},
ScheduleTimeMode: sharedschedule.TimeModeFixed,
CronExpr: "17 3 * * mon,wed,fri",
})
if err != nil {
t.Fatalf("normalizeSchedulePlan returned error: %v", err)
}
if plan.ScheduleKind != scheduleKindWeekly {
t.Fatalf("expected weekly schedule, got %q", plan.ScheduleKind)
}
if plan.ScheduleTimeMode != sharedschedule.TimeModeFixed {
t.Fatalf("expected fixed mode, got %q", plan.ScheduleTimeMode)
}
if plan.CronExpr != "17 3 * * mon,wed,fri" {
t.Fatalf("unexpected cron expression: %q", plan.CronExpr)
}
if plan.RandomWindowStart != defaultRandomWindowStart || plan.RandomWindowEnd != defaultRandomWindowEnd {
t.Fatalf("unexpected compatibility window: %s-%s", plan.RandomWindowStart, plan.RandomWindowEnd)
}
}
func TestNormalizeSchedulePlanRandomWindowAllowsEditableWindow(t *testing.T) {
plan, err := normalizeSchedulePlan(ScheduleTaskRequest{
ScheduleKind: scheduleKindWeekly,
ScheduleDays: []string{"mon", "wed", "fri"},
ScheduleTimeMode: sharedschedule.TimeModeRandomWindow,
RandomWindowStart: "02:00:00",
RandomWindowEnd: "04:30:00",
})
if err != nil {
t.Fatalf("normalizeSchedulePlan returned error: %v", err)
}
if plan.ScheduleKind != scheduleKindWeekly {
t.Fatalf("expected weekly schedule, got %q", plan.ScheduleKind)
}
if plan.ScheduleTimeMode != sharedschedule.TimeModeRandomWindow {
t.Fatalf("expected random window mode, got %q", plan.ScheduleTimeMode)
}
if plan.RandomWindowStart != "02:00:00" || plan.RandomWindowEnd != "04:30:00" {
t.Fatalf("unexpected random window: %s-%s", plan.RandomWindowStart, plan.RandomWindowEnd)
}
_, err = normalizeSchedulePlan(ScheduleTaskRequest{
ScheduleTimeMode: sharedschedule.TimeModeRandomWindow,
RandomWindowStart: "05:00:00",
RandomWindowEnd: "01:00:00",
})
if err == nil {
t.Fatal("expected inverted random window to be rejected")
}
}