I have several structs with fields of type time.Time
. I'm wondering what's the best practice to test them? Should I simply set the time.Time
fields to nil and test the rest of the struct (i.e. reflect.DeepEqual)? Otherwise is there a way make the time deterministic?
Given the function below how would you test it?
type mystruct struct {
s string
time time.Time
}
// myfunc receives a string and returns a struct of type mystruct
// with the same string and the current time.
func myfunc(s string) mystruct {
return mystruct{s: s, time: time.Now()}
}