add test for end date in incorrect format

Signed-off-by: zlawrence <zak.lawrence@zalando.de>
This commit is contained in:
zlawrence
2022-12-21 13:58:13 +01:00
parent 680e0feea1
commit c60253e90c
2 changed files with 14 additions and 1 deletions

View File

@ -331,7 +331,7 @@ func calculateMetrics(spec v1.ScalingScheduleSpec, defaultScalingWindow time.Dur
}
// If no end time was provided, set it to equal the start time
if schedule.EndDate == nil || *schedule.EndDate == "" {
if schedule.EndDate == nil || string(*schedule.EndDate) == "" {
scheduledEndTime = scheduledTime
} else {
scheduledEndTime, err = time.Parse(time.RFC3339, string(*schedule.EndDate))

View File

@ -249,6 +249,19 @@ func TestScalingScheduleCollector(t *testing.T) {
},
err: ErrInvalidScheduleDate,
},
{
msg: "Return error for one time config end date not in RFC3339 format",
schedules: []schedule{
{
date: nowTime.Add(-time.Minute * 20).Format(time.RFC3339),
endDate: nowTime.Add(1 * time.Hour).Format(time.RFC822),
kind: "OneTime",
duration: 15,
value: 100,
},
},
err: ErrInvalidScheduleDate,
},
{
msg: "Return the right value for two one time config",
schedules: []schedule{