Error asserting functions for table driven testcases.
Examples:
err := errors.New("not found")
tests := []struct {
input error
asserter ErrorAssertionFunc
}{
{
input: nil,
asserter: NoError(),
},
{
input: err,
asserter: Error(),
},
{
input: err,
asserter: ErrorIs(err),
},
{
input: fmt.Errorf("wrapped %w", err),
asserter: ErrorIs(err),
},
{
input: &os.PathError{},
asserter: ErrorOfType[*os.PathError](),
},
{
input: &os.PathError{Op: "op", Path: "/abc", Err: os.ErrInvalid},
asserter: ErrorOfType[*os.PathError](
func(tt TestingT, pe *os.PathError) { assert.Equal(tt, "op", pe.Op) },
),
},
{
input: fmt.Errorf("wrapped %w", &os.PathError{Op: "op", Path: "/abc", Err: os.ErrInvalid}),
asserter: All(
Error(),
ErrorIs(os.ErrInvalid),
ErrorOfType[*os.PathError](
func(tt TestingT, pe *os.PathError) { assert.Equal(tt, "op", pe.Op) },
),
ErrorStringContains("op"),
),
},
}