-
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
feat: add assert.Consistently #1606
base: master
Are you sure you want to change the base?
Conversation
This changeset adds the `assert.Consistently` and it's associated functions to assert that a condition is true over the entire period of `waitFor`. This is useful when testing the behavior of asynchronous functions. Closes stretchr#1087
a11e144
to
5e6e95d
Compare
I don't want more uses of |
We already have |
@dolmen, curious, what are the issues with |
|
Make sense, what would be the reversed condition asserter ? NotNever ? The name would be strange. But using another name that is not the opposite of Never would be strange no? |
In my opinion the opposite of
I don't have a strong preference on naming here. |
go func() { ch <- condition() }() | ||
case v := <-ch: | ||
if !v { | ||
return Fail(t, "Condition never satisfied", msgAndArgs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not sure if this is the right error message. To me, "Condition never satisfied" makes sense in the case of Eventually
. The term never is not applicable in the context of Consistently
.
}() | ||
case errs := <-ch: | ||
if len(errs) > 0 { | ||
return Fail(t, "Condition never satisfied", msgAndArgs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the errors to t
first before calling Fail
. Reference: https://github.com/stretchr/testify/blob/master/assert/assertions.go#L2017
If we are happy with
I missed the fact that |
Got it. So you would like to get rid of |
My only concern here is that using |
I was reluctant to add About the implementation, I think it's a bit early because we are not yet done with |
Summary
This changeset adds the
assert.Consistently
and it's associated functions to assert that a condition is true over the entire period ofwaitFor
. This is useful when testing the behavior of asynchronous functions.Changes
assert.Consistently
checks that a provided function is true for the entirety ofwaitFor
assert.Consistentlyf
checks that a provided function is true for the entirety ofwaitFor
and allows for formatting the error messageassert.ConsistentlyWithT
checks that a provided function that accepts atesting.T
is true for the entirety ofwaitFor
assert.ConsistentlyWithTf
checks that a provided function that accepts atesting.T
is true for the entirety ofwaitFor
and allows for formatting the error messageMotivation
See: #1087 (comment)
Related issues
Closes #1087