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

Implemented support for checkable errors #131

Merged
merged 9 commits into from May 12, 2024
Merged
23 changes: 15 additions & 8 deletions error_test.go
Expand Up @@ -9,20 +9,24 @@ import (

func TestIsAsError(t *testing.T) {
tcs := []struct {
err error
expected string
err error
expected string
expectedErr error
}{
{
err: fmt.Errorf("%w sample error: %v", ErrInvalidVersion, 123),
expected: "uuid: sample error: 123",
err: fmt.Errorf("%w sample error: %v", ErrInvalidVersion, 123),
expected: "uuid: sample error: 123",
expectedErr: ErrInvalidVersion,
},
{
err: fmt.Errorf("%w", ErrInvalidFormat),
expected: "uuid: invalid UUID format",
err: fmt.Errorf("%w", ErrInvalidFormat),
expected: "uuid: invalid UUID format",
expectedErr: ErrInvalidFormat,
},
{
err: fmt.Errorf("%w %q", ErrIncorrectFormatInString, "test"),
expected: "uuid: incorrect UUID format in string \"test\"",
err: fmt.Errorf("%w %q", ErrIncorrectFormatInString, "test"),
expected: "uuid: incorrect UUID format in string \"test\"",
expectedErr: ErrIncorrectFormatInString,
},
}
for i, tc := range tcs {
Expand All @@ -38,6 +42,9 @@ func TestIsAsError(t *testing.T) {
if !errors.As(tc.err, &uuidErr) {
dylan-bourque marked this conversation as resolved.
Show resolved Hide resolved
t.Error("expected errors.As() to work")
}
if !errors.Is(tc.err, tc.expectedErr) {
t.Errorf("expected error to be, or wrap, the %v sentinel error", tc.expectedErr)
}
})
}
}
Expand Down