Remove pkg/testutil/assert in favor of testify#32614
Conversation
|
SGTM
By design! So that someday we could do exactly this. At the time
|
|
I think the only thing missing from testify is a single line require.Error(t, err)
assert.Contains(t, err.Error(), expectedError)The problem is that I think this encourages people to skip checking the error message and only check that there is some error. Maybe we could leave |
|
You can do The difference between I only encountered one place where this came up. If it turns out to be generally useful, I'm fine with having a helper function to do it in a single line (perhaps in |
|
Ah, so there is |
|
Ah, yes, you need to use Most of the places in this PR unintentionally dropped the error string checking. I'll either add the helper or update tests to check for full error strings where appropriate. |
|
SGTM |
|
Updated the PR to restore error substring checking. Will work on converting |
|
@aaronlehmann at least on powerpc, tests are related |
|
Missed a |
I noticed that we're using a homegrown package for assertions. The functions are extremely similar to testify, but with enough slight differences to be confusing (for example, Equal takes its arguments in a different order). We already vendor testify, and it's used in a few places by tests. I also found some problems with pkg/testutil/assert. For example, the NotNil function seems to be broken. It checks the argument against "nil", which only works for an interface. If you pass in a nil map or slice, the equality check will fail. In the interest of avoiding NIH, I'm proposing replacing pkg/testutil/assert with testify. The test code looks almost the same, but we avoid the confusion of having two similar but slightly different assertion packages, and having to maintain our own package instead of using a commonly-used one. In the process, I found a few places where the tests should halt if an assertion fails, so I've made those cases (that I noticed) use "require" instead of "assert", and I've vendored the "require" package from testify alongside the already-present "assert" package. Signed-off-by: Aaron Lehmann <[email protected]>
|
Updated the PR to fully replace |
|
Wasn't testify horribly broken? I recall testify was rejected a while ago as well. |
|
I believe @icecrime has looked into this the last time testify was being discussed. |
|
How is it broken? Why is it better to have our own reimplementation? |
|
@aaronlehmann: I'm not saying we should have our own implementation. It's just that I recall there were objections to using testify. Some issues were brought up related to some bugs in testify. I'll look this up on the tracker and post here. |
|
@aaronlehmann: #10610 (comment) was the issue where some problems related to testify were brought up. I haven't used that code in a few years and I haven't checked if it's in a better condition since. My concern was mostly related to avoiding the package(s) if they have bugs/code quality issues. I don't have a strong opinion beyond that. |
|
That PR seems to be a bug fix opened by @icecrime. It was merged more than two years ago. I don't have a particular attachment to testify, though we use it in swarmkit and haven't encountered any bugs. However, I'm troubled that we've implemented our own |
|
as @aaronlehmann said, it seems like the issue in testify has been fixed upstream. I don't see a reason to not merge this one. LGTM |
| assert.Equal(t, expected, b.image) | ||
| assert.Equal(t, expected, b.from.ImageID()) | ||
| assert.Len(t, b.buildArgs.GetAllAllowed(), 0) | ||
| assert.Len(t, b.buildArgs.GetAllMeta(), 1) |
There was a problem hiding this comment.
I think this is a good example of an inconsistency in the design of testify.
assert.Len(), assert.Contains(), and assert.EqualError() have actual as the first arg, and expected as the second.
The args for assert.Equal(t, expected, actual) are in the opposite order. They should have been assert.Equal(t, actual, expected) to be consistent with the other assertions.
However I don't think that's enough of a reason to keep our own implementation.
|
LGTM |
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with
pkg/testutil/assert. For example, theNotNil function seems to be broken. It checks the argument against
nil, which only works for an interface. If you pass in a nil map orslice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assertwith testify. The test code looks almost the same,but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use
requireinstead of
assert, and I've vendored therequirepackage fromtestify alongside the already-present
assertpackage.cc @dnephin @vdemeester