I have the following function which adds given number of hours in current time and returns new time in a
func getExpiryTime(hour int) *string {
const layout = "2006-01-02T15:04:05Z"
expiryTime := time.Now().Local().Add(time.Hour *time.Duration(hour))
return aws.String(expiryTime.Format(layout))
}
What would be the best way to write unit test for this function?
You could try mocking the time provider and setting up the time.Now() function in your mock to return a preset value which you control. In production you can forward this to a call to the actual time.