forked from go-rel/rel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_go1.13_test.go
More file actions
50 lines (45 loc) · 1 KB
/
errors_go1.13_test.go
File metadata and controls
50 lines (45 loc) · 1 KB
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
// +build go1.13
package rel
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConstraintError_ErrorsIs(t *testing.T) {
tests := []struct {
err error
target error
equal bool
}{
{
err: ConstraintError{Type: CheckConstraint},
target: ErrCheckConstraint,
equal: true,
},
{
err: ConstraintError{Type: UniqueConstraint, Key: "username"},
target: ErrUniqueConstraint,
equal: true,
},
{
err: ErrUniqueConstraint,
target: ConstraintError{Type: UniqueConstraint, Key: "username"},
equal: true,
},
{
err: ConstraintError{Type: NotNullConstraint, Key: "username"},
target: ConstraintError{Type: NotNullConstraint, Key: "email"},
equal: false,
},
{
err: ConstraintError{Type: ForeignKeyConstraint, Key: "book_id"},
target: ErrNotFound,
equal: false,
},
}
for _, test := range tests {
t.Run(test.err.Error(), func(t *testing.T) {
assert.Equal(t, test.equal, errors.Is(test.err, test.target))
})
}
}