forked from go-gorm/sqlserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_translator_test.go
46 lines (42 loc) · 944 Bytes
/
error_translator_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
package sqlserver
import (
"errors"
"testing"
"gorm.io/gorm"
"github.com/microsoft/go-mssqldb"
)
func TestDialector_Translate(t *testing.T) {
type fields struct {
Config *Config
}
type args struct {
err error
}
tests := []struct {
name string
fields fields
args args
want error
}{
{
name: "it should return ErrDuplicatedKey error if the error number is 2627",
args: args{err: mssql.Error{Number: 2627}},
want: gorm.ErrDuplicatedKey,
},
{
name: "it should return ErrForeignKeyViolated the error number is 547",
args: args{err: mssql.Error{Number: 547}},
want: gorm.ErrForeignKeyViolated,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dialector := Dialector{
Config: tt.fields.Config,
}
if err := dialector.Translate(tt.args.err); !errors.Is(err, tt.want) {
t.Errorf("Translate() expected error = %v, got error %v", err, tt.want)
}
})
}
}