tests: migrate to assert.ErrorContains when possible
If we have an error type that we're checking a substring against, we
should really be checking using ErrorContains to indicate the right
semantics to assert.
Mostly done using these transforms:
find . -type f -name "*_test.go" | \
xargs gofmt -w -r 'assert.Assert(t, is.ErrorContains(e, s)) -> assert.ErrorContains(t, e, s)'
find . -type f -name "*_test.go" | \
xargs gofmt -w -r 'assert.Assert(t, is.Contains(err.Error(), s)) -> assert.ErrorContains(t, err, s)'
find . -type f -name "*_test.go" | \
xargs gofmt -w -r 'assert.Check(t, is.Contains(err.Error(), s)) -> assert.Check(t, is.ErrorContains(err, s))'
As well as some small fixups to helpers that were doing
strings.Contains explicitly.
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
@ -324,7 +324,7 @@ func TestCheckoutGit(t *testing.T) {
|
||||
assert.Check(t, is.Equal("subcontents", string(b)))
|
||||
} else {
|
||||
_, err := os.Stat(filepath.Join(r, "sub/subfile"))
|
||||
assert.Assert(t, is.ErrorContains(err, ""))
|
||||
assert.ErrorContains(t, err, "")
|
||||
assert.Assert(t, os.IsNotExist(err))
|
||||
}
|
||||
|
||||
@ -373,6 +373,8 @@ func TestGitInvalidRef(t *testing.T) {
|
||||
for _, url := range gitUrls {
|
||||
_, err := Clone(url)
|
||||
assert.Assert(t, err != nil)
|
||||
// On Windows, git has different case for the "invalid refspec" error,
|
||||
// so we can't use ErrorContains.
|
||||
assert.Check(t, is.Contains(strings.ToLower(err.Error()), "invalid refspec"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user