-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from vshn/refactor-timeofday
Refactor time of day in maintenance
- Loading branch information
Showing
17 changed files
with
286 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/utils/ptr" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func Test_GetTime(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
scheduleSpec VSHNDBaaSMaintenanceScheduleSpec | ||
want string | ||
}{ | ||
{ | ||
name: "GivenNormalSchedule_ThenExpectCorrectTimeOfDay", | ||
scheduleSpec: VSHNDBaaSMaintenanceScheduleSpec{ | ||
TimeOfDay: TimeOfDay("00:30:00"), | ||
}, | ||
want: "00:30:00", | ||
}, | ||
{ | ||
name: "GivenEmptyTimeOfDay_ThenExpectZeroTimeOfDay", | ||
scheduleSpec: VSHNDBaaSMaintenanceScheduleSpec{ | ||
TimeOfDay: TimeOfDay(""), | ||
}, | ||
want: "00:00:00", | ||
}, | ||
{ | ||
name: "GivenNoTimeOfDay_ThenExpectZeroTimeOfDay", | ||
scheduleSpec: VSHNDBaaSMaintenanceScheduleSpec{}, | ||
want: "00:00:00", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actualTime := tt.scheduleSpec.TimeOfDay.GetTime() | ||
assert.Equal(t, tt.want, actualTime.Format(time.TimeOnly)) | ||
}) | ||
} | ||
} | ||
|
||
func Test_AddTime(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
scheduleSpec VSHNDBaaSMaintenanceScheduleSpec | ||
d time.Duration | ||
want string | ||
}{ | ||
{ | ||
name: "GivenNormalSchedule_ThenExpectAddedTimeOfDay", | ||
scheduleSpec: VSHNDBaaSMaintenanceScheduleSpec{ | ||
TimeOfDay: TimeOfDay("00:30:00"), | ||
}, | ||
d: 60 * time.Minute, | ||
want: "01:30:00", | ||
}, | ||
{ | ||
name: "GivenEmptyTimeOfDay_ThenExpectAddedTimeOfDay", | ||
scheduleSpec: VSHNDBaaSMaintenanceScheduleSpec{ | ||
TimeOfDay: TimeOfDay(""), | ||
}, | ||
d: 10 * time.Minute, | ||
want: "00:10:00", | ||
}, | ||
{ | ||
name: "GivenNoTimeOfDay_ThenExpectAddedTimeOfDay", | ||
scheduleSpec: VSHNDBaaSMaintenanceScheduleSpec{}, | ||
d: 5 * time.Minute, | ||
want: "00:05:00", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actualTime := tt.scheduleSpec.TimeOfDay.AddTime(tt.d) | ||
assert.Equal(t, tt.want, string(actualTime)) | ||
}) | ||
} | ||
} | ||
|
||
func Test_IsSet(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
timeOfDay *TimeOfDay | ||
want bool | ||
}{ | ||
{ | ||
name: "GivenNormalSchedule_ThenExpectIsTrue", | ||
timeOfDay: ptr.To[TimeOfDay]("00:00:00"), | ||
want: true, | ||
}, | ||
{ | ||
name: "GivenEmptyTimeOfDay_ThenExpectIsFalse", | ||
timeOfDay: ptr.To[TimeOfDay](""), | ||
want: false, | ||
}, | ||
{ | ||
name: "GivenEmptyTimeOfDay_ThenExpectIsFalse", | ||
timeOfDay: nil, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.want, tt.timeOfDay.IsSet()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.