@@ -2125,10 +2125,13 @@ func TestGetSwitchoverSchedule(t *testing.T) {
21252125 pastWindowTimeStart := pastTimeStart .Format ("15:04" )
21262126 pastWindowTimeEnd := now .Add (- 1 * time .Hour ).Format ("15:04" )
21272127
2128+ defaultWindowStr := fmt .Sprintf ("%s-%s" , futureWindowTimeStart , futureWindowTimeEnd )
2129+
21282130 tests := []struct {
2129- name string
2130- windows []acidv1.MaintenanceWindow
2131- expected string
2131+ name string
2132+ windows []acidv1.MaintenanceWindow
2133+ defaultWindows []string
2134+ expected string
21322135 }{
21332136 {
21342137 name : "everyday maintenance windows is later today" ,
@@ -2190,11 +2193,40 @@ func TestGetSwitchoverSchedule(t *testing.T) {
21902193 },
21912194 expected : pastTimeStart .AddDate (0 , 0 , 1 ).Format ("2006-01-02T15:04+00" ),
21922195 },
2196+ {
2197+ name : "fallback to operator default window when spec is empty" ,
2198+ windows : []acidv1.MaintenanceWindow {},
2199+ defaultWindows : []string {defaultWindowStr },
2200+ expected : futureTimeStart .Format ("2006-01-02T15:04+00" ),
2201+ },
2202+ {
2203+ name : "no windows defined returns empty string" ,
2204+ windows : []acidv1.MaintenanceWindow {},
2205+ defaultWindows : nil ,
2206+ expected : "" ,
2207+ },
2208+ {
2209+ name : "choose the earliest window from multiple in spec" ,
2210+ windows : []acidv1.MaintenanceWindow {
2211+ {
2212+ Weekday : now .AddDate (0 , 0 , 2 ).Weekday (),
2213+ StartTime : mustParseTime (futureWindowTimeStart ),
2214+ EndTime : mustParseTime (futureWindowTimeEnd ),
2215+ },
2216+ {
2217+ Weekday : now .AddDate (0 , 0 , 1 ).Weekday (),
2218+ StartTime : mustParseTime (pastWindowTimeStart ),
2219+ EndTime : mustParseTime (pastWindowTimeEnd ),
2220+ },
2221+ },
2222+ expected : pastTimeStart .AddDate (0 , 0 , 1 ).Format ("2006-01-02T15:04+00" ),
2223+ },
21932224 }
21942225
21952226 for _ , tt := range tests {
21962227 t .Run (tt .name , func (t * testing.T ) {
21972228 cluster .Spec .MaintenanceWindows = tt .windows
2229+ cluster .OpConfig .MaintenanceWindows = tt .defaultWindows
21982230 schedule := cluster .getSwitchoverScheduleAtTime (now )
21992231 if schedule != tt .expected {
22002232 t .Errorf ("Expected GetSwitchoverSchedule to return %s, returned: %s" , tt .expected , schedule )
0 commit comments