Skip to content

Commit

Permalink
Remove TODO about cmpopts.EquateErrors
Browse files Browse the repository at this point in the history
I tried to address this TODO today, but found that I kind of prefer how our
implementation works. I've found from time to time while writing tests that
I was accidentally wrapping my errors with the wrong context (i.e. message),
which is not something the cmpopts variant tests for.

Signed-off-by: Nic Cope <[email protected]>
  • Loading branch information
negz committed Sep 9, 2021
1 parent e248b13 commit 8c7ddfb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/test/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import (
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// TODO(negz): Replace this if a similar option is added to cmpopts per
// https://github.com/google/go-cmp/issues/89

// EquateErrors returns true if the supplied errors are of the same type and
// produce identical strings. This mirrors the error comparison behaviour of
// https://github.com/go-test/deep, which most Crossplane tests targeted before
// we switched to go-cmp.
//
// This differs from cmpopts.EquateErrors, which does not test for error strings
// and instead returns whether one error 'is' (in the errors.Is sense) the
// other.
func EquateErrors() cmp.Option {
return cmp.Comparer(func(a, b error) bool {
if a == nil || b == nil {
Expand Down

0 comments on commit 8c7ddfb

Please sign in to comment.