...
1
16
17 package errormatch
18
19 import (
20 "testing"
21
22 "github.com/stretchr/testify/assert"
23 "k8s.io/utils/ptr"
24 )
25
26 type Matcher func(t testing.TB, err error) bool
27
28 func newMatcherPtr(matcher Matcher) *Matcher {
29 return ptr.To(matcher)
30 }
31
32 func NoError() *Matcher {
33 return newMatcherPtr(func(tb testing.TB, err error) bool {
34 tb.Helper()
35
36 return assert.NoError(tb, err)
37 })
38 }
39
40 func ErrorContains(contains string) *Matcher {
41 return newMatcherPtr(func(tb testing.TB, err error) bool {
42 tb.Helper()
43
44 return assert.ErrorContains(tb, err, contains)
45 })
46 }
47
View as plain text