-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
Failed comparison of identical time variables #264
Comments
Thanks @wolfgangmeyers ! I was able to reproduce the problem. I have also tried to add some Printf:
And this is the result:
It seems that We could potentially catch that in |
Cool investigation @nodo. I sort of wonder whether there's use in having a separate set of time related matchers. I can definitely see how it would be nice to have |
Yes this bites folks a lot. The issue, as you've observed @nodo, is a mismatch in timezones. This could be solved with a time matcher (I believe the little known ...but the real pain point is when you have mismatched time zones for time objects buried inside a struct. A recent example of this bit a team at Pivotal where a struct contained a field of type Any thoughts on what we can do here? |
In the example code I pasted, I believe the timezones are pacific for both the original and copy. |
@wolfgangmeyers you might need to try |
We could do something similar to what I proposed here #161 (comment) and just change the message to make it less confusing. For instance here: https://github.com/onsi/gomega/blob/master/format/format.go#L197 we could catch the case when the value is a time and print the location as well. The code would be something like: default:
t, ok := object.(time.Time)
if !ok {
return fmt.Sprintf("%T", object)
}
return fmt.Sprintf("%T | Location: %s", t, t.Location()) and the message would be something like:
It's a bit of a hack, but I couldn't think of any other alternative. WDYT? Unfortunately, this approach does not completely solves the case of complex struct with times nested inside. That requires a more complex workaround. |
So I have an update. I got an error again when checking two time variables that should have been identical. When serialized with json and deserialized, at first they appeared to be identical (from the error output), but when printing them out with log.Printf I noticed that the first value (from time.Now()) has an additional "monotonic" component. The timezones were identical in the output, so I don't think they are causing the problem:
I think the monotonic portion - which according to the go docs, is only used for debugging - is causing the difference. Could the matcher be updated to ignore the monotonic component? The docs describing this can be found here: https://github.com/golang/go/blob/master/src/time/format.go#L431 |
Sorry for the delay @wolfgangmeyers. Would It seems that handling this in Any opinions on that? |
I think that works for me. I know I would have seen this if I had read completely through the docs, but it would be nice if it were more obvious. Thanks for pointing it out! 😄 |
Still an issue in v1.5.0 and go1.12.6. |
FTW
|
I manage to reproduce that. Its probably because gomega doesn't call time.Equal(). |
I agree this issue should be reopened. |
When I try comparing two time variables in a test:
It fails with output like this:
I think that the
Equal
matcher should identify the two time variables as being equal.The text was updated successfully, but these errors were encountered: