Skip to content
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

assert: Add Error and remove google/go-cmp #74

Merged
merged 3 commits into from
Dec 15, 2019
Merged

assert: Add Error and remove google/go-cmp #74

merged 3 commits into from
Dec 15, 2019

Conversation

nhooyr
Copy link
Contributor

@nhooyr nhooyr commented Dec 12, 2019

No description provided.

// ErrorContains asserts err != nil and err.Error() contains sub.
//
// The match will be case insensitive.
func ErrorContains(t testing.TB, err error, sub, name string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer a function to ensure the two unwrapped errors are equal instead of just comparing strings

I often have to do things like this
https://github.com/cdr/enterprise/blob/master/manager/internal/database/teams_test.go#L46

Additionally, if you call xerrors.Unwrap on a non-wrapped error it returns nil instead of the input err. Would be nice to handle that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using ErrorContains in nhooyr/websocket but I can easily fix that. Will adjust this function.

@nhooyr nhooyr requested a review from coadler December 12, 2019 21:52
@nhooyr nhooyr changed the title assert: Add Error and ErrorContains assert: Add Error and handle error unwrapping in Equal Dec 12, 2019
@nhooyr nhooyr force-pushed the more-assert branch 2 times, most recently from 94611f7 to 1e111e4 Compare December 12, 2019 21:53
@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 13, 2019

@coadler what do you think about adding ...cmp.Options to Equals? I think name is enough for adding detail instead of a ...slog.F.

@coadler
Copy link
Member

coadler commented Dec 13, 2019

I could see some benefit in that. Right now we have to truncate all of our time.Times because ones returned from Postgres lose a bit of precision. If we could make a cmd.Option to manually compare them that would help a lot.

@nhooyr nhooyr requested a review from coadler December 14, 2019 00:42
See google/go-cmp#174

In general its a very heavy library and I'm not convinced
it offers enough.
@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 14, 2019

@coadler Thoughts on removing google/go-cmp? Do you approve?

@nhooyr nhooyr changed the title assert: Add Error and handle error unwrapping in Equal assert: Add Error and remove google/go-cmp Dec 15, 2019
@nhooyr nhooyr merged commit 82a5884 into master Dec 15, 2019
@nhooyr nhooyr deleted the more-assert branch December 15, 2019 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants