-
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
Testify assert.Equal
between two times doesn't work same as (time.Time).Equal
.
#1010
Comments
Is possible to do this repo eligible for https://hacktoberfest.digitalocean.com/ ?? @glesica @boyan-soubachov @mvdkleijn |
There was a similar PR merged a while back, but the change seems to have disappeared. #979 |
I can confirm this. I have no problem with creating a PR for this but then the desired behavior needs to be clear. IMHO there are 2 use cases that need to be addresed:
Ideally you can define the behavior you want. At this moment assert is setup as a singleton so it will require some work to define the time comparison 'style' as an option (e.g. a := NewAssert(USE_TIME_EQUAL_METHOD), a.Equal(t, time1, time2) ) so maybe it is better to discriminate using methods. Then I would propose that methods like |
I agree that the Is using the func TestTime(t *testing.T) {
start := time.Now()
assert.True(t, start.Equal(start))
assert.WithinDuration(t, start, start, 0)
} |
I think this is answered, and is related to #1204 |
Motivation
Before using
testify
I used to test mytime.Time
objects like this:Once I started using testify, my intuition was replace the above test with
Which mostly worked fine.... until not. I notice that two objects with different locations but representing same time instant were considered as not equal... I stopped using
assert.Equal
to compare objectstime.Time
but instead, usingThis way to use the library feels tricky, uncomfortable and lose the idiomatic meaningful. I don't want to assert a boolean, but two
time.Time
objects instead 😔I propose to use built-in Equal for
time.Time
objects.Considering this case could be translatable to any object with a method
<T>.Equal(<T>) bool
. Maybe checking existence of such method and using it, is a good approach.Thanks for your consideration
The text was updated successfully, but these errors were encountered: