-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require.Equal: Comparing time.Time after marshalling and unmarshalling is not correct #502
Comments
Same issue here. |
See golang/go#19502. To summarize the link: this is how the time package works. Marshalling the time drops the monotonic clock reading, as that only has meaning within the current process. Round trip marshalling and unmarshalling of times will produce different structs. |
We should use There's an issue to track that here: #535 Contributions more than welcome :) |
Since #535 is kind of stuck, maybe we should add a special case to time.Time? |
@posener unfortunately, that would require implementing our own version of |
Any progress on this? |
We just used |
Comparing Time values with require.Equal fails because one of the arguments has a monotonic clock reading and because require.Equal doesn't use time.Equal for comparison [1]. [1] stretchr/testify#502
Comparing Time values with require.Equal fails because one of the arguments has a monotonic clock reading and because require.Equal doesn't use time.Equal for comparison [1]. [1] stretchr/testify#502
Any progress on this? |
|
@boyan-soubachov Maybe we can use the solution of #951 on the |
The code for |
a workaround for me was |
When testing sending data that contains a
time.Time
via JSON the sent data and received data are not equal according torequire.Equal
.Sample unit test:
Equal diff output:
A possible solution would be having a special comparison for
time.Time
fields using for example Unix timestamps.The text was updated successfully, but these errors were encountered: