google / go-cmp

Package for comparing Go values in tests
BSD 3-Clause "New" or "Revised" License
4.08k stars 209 forks source link

cmpopts EquateApproxTime doesn't handle time.Time as map keys #333

Closed nahojer closed 11 months ago

nahojer commented 12 months ago

It seems that cmpopts.EquateApproxTime doesn't handle the case when the type is of e.g. map[time.Time]string. But maybe this is by design?

dsnet commented 12 months ago

Hi, this is working as intended, the documentation says:

Maps are equal if they are both nil or both non-nil, where recursively calling Equal on all non-ignored map entries report equal. Map keys are equal according to the == operator. To use custom comparisons for map keys, consider using cmpopts.SortMaps. Empty non-nil maps and nil maps are not equal; to equate empty maps, consider using cmpopts.EquateEmpty.

It provides alternative solutions such as using cmpopts.SortMaps.

nahojer commented 11 months ago

Thanks for clarifying! Closing this issue.