MCPcopy Create free account
hub / github.com/dataddo/pgq / Test_isErrorCode

Function Test_isErrorCode

errors_test.go:44–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42)
43
44func Test_isErrorCode(t *testing.T) {
45 type args struct {
46 err error
47 codes []string
48 }
49 tests := []struct {
50 name string
51 args args
52 want bool
53 }{
54 {
55 name: "test wrapped pg error",
56 args: args{
57 codes: []string{"42P01"},
58 err: fmt.Errorf("foo: %w",
59 &pgErrorImplementation{
60 sqlState: "42P01",
61 },
62 ),
63 },
64 want: true,
65 },
66 {
67 name: "test wrapped legacy error",
68 args: args{
69 codes: []string{"42P01"},
70 err: fmt.Errorf("foo: %w",
71 &legacyPGErrorImplementation{
72 err: errors.New("test"),
73 fatal: true,
74 codes: map[byte]string{
75 'C': "42P01",
76 },
77 },
78 ),
79 },
80 want: true,
81 },
82 }
83 for _, tt := range tests {
84 t.Run(tt.name, func(t *testing.T) {
85 if got := isErrorCode(tt.args.err, tt.args.codes...); got != tt.want {
86 t.Errorf("isErrorCode() = %v, want %v", got, tt.want)
87 }
88 })
89 }
90}

Callers

nothing calls this directly

Calls 2

isErrorCodeFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected