-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_test.go
56 lines (49 loc) · 1.17 KB
/
grpc_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
55
56
package ginerrors_test
import (
"database/sql"
"testing"
ginerrors "github.com/spacetab-io/errors-gin-go"
"github.com/stretchr/testify/assert"
)
const (
unknownErrMessage = "rpc error: code = InvalidArgument desc = unknown error value"
recordNotFountMessage = "rpc error: code = NotFound desc = record not found"
unavailableMethodMessage = "rpc error: code = Unavailable desc = method not allowed"
)
func TestWrapErrWithRPC(t *testing.T) {
cases := []struct {
caseName string
err error
lang string
expected string
}{
{
caseName: "unknown err",
err: ginerrors.ErrUnknownErrVal,
lang: "en",
expected: unknownErrMessage,
},
{
caseName: "sql err",
err: sql.ErrNoRows,
lang: "en",
expected: recordNotFountMessage,
},
{
caseName: "unavailable method",
err: ginerrors.ErrNoMethod,
lang: "en",
expected: unavailableMethodMessage,
},
}
t.Parallel()
for _, cc := range cases {
cc := cc
t.Run(cc.caseName, func(t *testing.T) {
t.Parallel()
err := ginerrors.WrapErrorWithStatus(cc.err, cc.lang)
assert.Error(t, err)
assert.Equal(t, cc.expected, err.Error())
})
}
}