-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
enhancementpkg-assertChange related to package testify/assertChange related to package testify/asserttype-TimeRelated to type time.Time or the time packageRelated to type time.Time or the time package
Description
It is hard to test equality on structs when having instant created time.Time objects in test time. When I test these cases I use to assert equality field by field, and for those time.Time or *time.Time fields I user assert.WithinDuration with some time.Duration delta.
Example
type SubStruct struct {
Number int
TimeField time.Time
}
type TestStruct struct {
ID int
Name string
StartTime time.Time
EndTime *time.Time
Sub SubStruct
}
// to test equality on TestStruct I go with the following
assert.Equal(t, expected.ID, resulted.ID)
// rest of fields
assert.WithinDuration(t, expected.StartTime, resulted.StartTime, time.Second)
What I think would be nice is something like the following (beyond naming)
assert.EqualWithinDuration(t, expected, resulted, time.Second)
pcha, ptsypyshev, cosban, alc6 and raynbovv
Metadata
Metadata
Assignees
Labels
enhancementpkg-assertChange related to package testify/assertChange related to package testify/asserttype-TimeRelated to type time.Time or the time packageRelated to type time.Time or the time package