...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v3rpc
16
17 import (
18 "context"
19 "errors"
20 "testing"
21
22 "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
23 "go.etcd.io/etcd/server/v3/mvcc"
24
25 "google.golang.org/grpc/codes"
26 "google.golang.org/grpc/status"
27 )
28
29 func TestGRPCError(t *testing.T) {
30 tt := []struct {
31 err error
32 exp error
33 }{
34 {err: mvcc.ErrCompacted, exp: rpctypes.ErrGRPCCompacted},
35 {err: mvcc.ErrFutureRev, exp: rpctypes.ErrGRPCFutureRev},
36 {err: context.Canceled, exp: context.Canceled},
37 {err: context.DeadlineExceeded, exp: context.DeadlineExceeded},
38 {err: errors.New("foo"), exp: status.Error(codes.Unknown, "foo")},
39 }
40 for i := range tt {
41 if err := togRPCError(tt[i].err); err != tt[i].exp {
42 if _, ok := status.FromError(err); ok {
43 if err.Error() == tt[i].exp.Error() {
44 continue
45 }
46 }
47 t.Errorf("#%d: got %v, expected %v", i, err, tt[i].exp)
48 }
49 }
50 }
51
View as plain text