Skip to content

Commit

Permalink
Added expected err errors.Is() checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Lindahl committed Apr 10, 2024
1 parent 0342a6a commit e38c6ae
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions error_test.go
Original file line number Diff line number Diff line change
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) {
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

0 comments on commit e38c6ae

Please sign in to comment.