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.
This commit is contained in:
parent
2c57498e43
commit
446c134797
|
|
@ -1767,9 +1767,13 @@ func (c *Cluster) GetStatus() *ClusterStatus {
|
|||
}
|
||||
|
||||
func (c *Cluster) GetSwitchoverSchedule() string {
|
||||
now := time.Now().UTC()
|
||||
return c.GetSwitchoverScheduleAtTime(now)
|
||||
}
|
||||
|
||||
func (c *Cluster) GetSwitchoverScheduleAtTime(now time.Time) string {
|
||||
var possibleSwitchover, schedule time.Time
|
||||
|
||||
now := time.Now().UTC()
|
||||
for _, window := range c.Spec.MaintenanceWindows {
|
||||
// in the best case it is possible today
|
||||
possibleSwitchover = time.Date(now.Year(), now.Month(), now.Day(), window.StartTime.Hour(), window.StartTime.Minute(), 0, 0, time.UTC)
|
||||
|
|
|
|||
|
|
@ -2116,7 +2116,7 @@ func TestCompareVolumeMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetSwitchoverSchedule(t *testing.T) {
|
||||
now := time.Now()
|
||||
now, _ := time.Parse(time.RFC3339, "2025-11-11T12:35:00Z")
|
||||
|
||||
futureTimeStart := now.Add(1 * time.Hour)
|
||||
futureWindowTimeStart := futureTimeStart.Format("15:04")
|
||||
|
|
@ -2195,7 +2195,7 @@ func TestGetSwitchoverSchedule(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cluster.Spec.MaintenanceWindows = tt.windows
|
||||
schedule := cluster.GetSwitchoverSchedule()
|
||||
schedule := cluster.GetSwitchoverScheduleAtTime(now)
|
||||
if schedule != tt.expected {
|
||||
t.Errorf("Expected GetSwitchoverSchedule to return %s, returned: %s", tt.expected, schedule)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue