-
Notifications
You must be signed in to change notification settings - Fork 9
/
errors_test.go
54 lines (48 loc) · 926 Bytes
/
errors_test.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
51
52
53
54
package pggen
import (
"fmt"
"testing"
"github.com/opendoor/pggen/unstable"
)
func TestIsNotFoundError(t *testing.T) {
type testCase struct {
err error
is bool
}
cases := []testCase{
{
err: fmt.Errorf("NonNotFound1"),
is: false,
},
{
err: &unstable.NotFoundError{Msg: "NotFound1"},
is: true,
},
{
err: &causedErr{cause: &unstable.NotFoundError{Msg: "NotFound2"}},
is: true,
},
{
err: &causedErr{cause: fmt.Errorf("NonNotFound2")},
is: false,
},
}
for i := range cases {
c := cases[i]
t.Run(c.err.Error(), func(t *testing.T) {
if IsNotFoundError(c.err) != c.is {
t.Fatalf("expected %t, got %t", c.is, !c.is)
}
})
}
}
// we define this manually rather than using %w to maintain our msgv
type causedErr struct {
cause error
}
func (ce *causedErr) Error() string {
return ce.cause.Error()
}
func (ce *causedErr) Unwrap() error {
return ce.cause
}