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 <felix-kunde@gmx.de> Co-authored-by: Mikkel Oscar Lyderik Larsen <mikkeloscar@users.noreply.github.com>
This commit is contained in:
parent
5aa8f961ec
commit
cd05682482
|
|
@ -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