I'm following another answer here: Is there an easy way to stub out time.Now() globally during test?
So I have this file where I do something like:
var timeNow = time.Now
func GenerateTimestamp() int64 {
now := timeNow() // current local time
sec := now.Unix() // number of seconds since January 1, 1970 UTC
return sec // int 64
}
We use GenerateTimestamp() in another function
func AddTs() {
// Some if check, use GenerateTimestamp() here
}
Now on my test file, I am doing something like:
now := time.Now()
timeNow = func() int64 {
// fmt.Println("looking for this", now.Unix())
return now.Unix()
}
I am getting this error cannot use func literal (type func() int64) as type func() time.Time in assignment
. I need to be able to return an int64 type (which my original function returns), how can I get around this?
Feel free to point me to docs, I am a Go newbie!!