generated from ebi-yade/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
50 lines (41 loc) · 996 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cases
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
)
type ErrorCheck func(*testing.T, error)
func NoError(t *testing.T, err error) {
t.Helper()
require.NoError(t, err)
}
func Error(t *testing.T, err error) {
t.Helper()
require.Error(t, err)
}
func ErrorIs(target error) ErrorCheck {
return func(t *testing.T, err error) {
t.Helper()
require.ErrorIs(t, err, target)
}
}
func ErrorAs(target error) ErrorCheck {
return func(t *testing.T, err error) {
t.Helper()
require.ErrorAs(t, err, target)
}
}
func ErrorMsg(target string) ErrorCheck {
return func(t *testing.T, err error) {
t.Helper()
require.Error(t, err)
require.Equal(t, target, err.Error())
}
}
func ErrorNoDiff(target error, cmpOpts ...cmp.Option) ErrorCheck {
return func(t *testing.T, err error) {
t.Helper()
require.Error(t, err, "If you expected no error, use cases.NoError instead")
require.Empty(t, cmp.Diff(target, err, cmpOpts...))
}
}