mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-28 01:03:50 +08:00
63 lines
2.3 KiB
Go
63 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
)
|
|
|
|
func TestEvaluateScheduleWindowWeeklyCrossMidnight(t *testing.T) {
|
|
s := &db.TaskSchedule{ScheduleType: "weekly", TimezoneMode: "beijing", Weekdays: []int{1, 2, 3, 4, 5}, StartTime: "18:00:00", EndTime: "09:00:00"}
|
|
// Tuesday 08:00 is still inside Monday's overnight window.
|
|
w := evaluateScheduleWindow(s, time.Date(2026, 10, 6, 8, 0, 0, 0, time.FixedZone("CST", 8*3600)))
|
|
if !w.active {
|
|
t.Fatal("expected overnight window to be active")
|
|
}
|
|
// Saturday 10:00 is outside the work-week window.
|
|
w = evaluateScheduleWindow(s, time.Date(2026, 10, 10, 10, 0, 0, 0, time.FixedZone("CST", 8*3600)))
|
|
if w.active {
|
|
t.Fatal("expected weekend to be outside")
|
|
}
|
|
}
|
|
|
|
func TestEvaluateScheduleWindowOnce(t *testing.T) {
|
|
s := &db.TaskSchedule{ScheduleType: "once", TimezoneMode: "beijing", RunDate: "2026-10-09", StartTime: "18:00:00", EndTime: "23:00:00"}
|
|
loc := time.FixedZone("CST", 8*3600)
|
|
if w := evaluateScheduleWindow(s, time.Date(2026, 10, 9, 17, 59, 0, 0, loc)); w.active {
|
|
t.Fatal("one-shot fired early")
|
|
}
|
|
if w := evaluateScheduleWindow(s, time.Date(2026, 10, 9, 19, 0, 0, 0, loc)); !w.active {
|
|
t.Fatal("one-shot should be active")
|
|
}
|
|
if w := evaluateScheduleWindow(s, time.Date(2026, 10, 10, 0, 0, 0, 0, loc)); !w.complete {
|
|
t.Fatal("one-shot should be complete")
|
|
}
|
|
}
|
|
|
|
func TestEvaluateScheduleWindowOpenEnded(t *testing.T) {
|
|
s := &db.TaskSchedule{ScheduleType: "weekly", TimezoneMode: "beijing", Weekdays: []int{6}, StartTime: "09:00:00"}
|
|
loc := time.FixedZone("CST", 8*3600)
|
|
if w := evaluateScheduleWindow(s, time.Date(2026, 10, 10, 10, 0, 0, 0, loc)); !w.active {
|
|
t.Fatal("open-ended weekly schedule should stay active")
|
|
}
|
|
}
|
|
|
|
func TestEvaluateScheduleWindowOnceDateRange(t *testing.T) {
|
|
s := &db.TaskSchedule{
|
|
ScheduleType: "once",
|
|
TimezoneMode: "beijing",
|
|
RunDate: "2026-10-09",
|
|
EndDate: "2026-10-11",
|
|
StartTime: "18:00:00",
|
|
EndTime: "09:00:00",
|
|
}
|
|
loc := time.FixedZone("CST", 8*3600)
|
|
if w := evaluateScheduleWindow(s, time.Date(2026, 10, 10, 12, 0, 0, 0, loc)); !w.active {
|
|
t.Fatal("date-range one-shot should remain active between its dates")
|
|
}
|
|
if w := evaluateScheduleWindow(s, time.Date(2026, 10, 11, 9, 0, 0, 0, loc)); !w.complete || w.active {
|
|
t.Fatal("date-range one-shot should complete at its end date and time")
|
|
}
|
|
}
|