Skip to content

Commit cd05682

Browse files
berlerFxKumikkeloscar
authored
fix switchover schedule tests (#2995)
* fix switchover schedule tests Previously the tests would fail depending on the local time zone and the time of day the test was being run. --------- Co-authored-by: Felix Kunde <[email protected]> Co-authored-by: Mikkel Oscar Lyderik Larsen <[email protected]>
1 parent 5aa8f96 commit cd05682

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/cluster/cluster.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,9 +1767,13 @@ func (c *Cluster) GetStatus() *ClusterStatus {
17671767
}
17681768

17691769
func (c *Cluster) GetSwitchoverSchedule() string {
1770+
now := time.Now().UTC()
1771+
return c.getSwitchoverScheduleAtTime(now)
1772+
}
1773+
1774+
func (c *Cluster) getSwitchoverScheduleAtTime(now time.Time) string {
17701775
var possibleSwitchover, schedule time.Time
17711776

1772-
now := time.Now().UTC()
17731777
for _, window := range c.Spec.MaintenanceWindows {
17741778
// in the best case it is possible today
17751779
possibleSwitchover = time.Date(now.Year(), now.Month(), now.Day(), window.StartTime.Hour(), window.StartTime.Minute(), 0, 0, time.UTC)

pkg/cluster/cluster_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ func TestCompareVolumeMounts(t *testing.T) {
21162116
}
21172117

21182118
func TestGetSwitchoverSchedule(t *testing.T) {
2119-
now := time.Now()
2119+
now, _ := time.Parse(time.RFC3339, "2025-11-11T12:35:00Z")
21202120

21212121
futureTimeStart := now.Add(1 * time.Hour)
21222122
futureWindowTimeStart := futureTimeStart.Format("15:04")
@@ -2195,7 +2195,7 @@ func TestGetSwitchoverSchedule(t *testing.T) {
21952195
for _, tt := range tests {
21962196
t.Run(tt.name, func(t *testing.T) {
21972197
cluster.Spec.MaintenanceWindows = tt.windows
2198-
schedule := cluster.GetSwitchoverSchedule()
2198+
schedule := cluster.getSwitchoverScheduleAtTime(now)
21992199
if schedule != tt.expected {
22002200
t.Errorf("Expected GetSwitchoverSchedule to return %s, returned: %s", tt.expected, schedule)
22012201
}

0 commit comments

Comments
 (0)