MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestEncodeDecodeStatus

Function TestEncodeDecodeStatus

extgrpc/ext_grpc_test.go:90–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestEncodeDecodeStatus(t *testing.T) {
91 testcases := []struct {
92 desc string
93 makeStatus func(*testing.T, codes.Code, string, []proto.Message) statusIface
94 fromError func(err error) statusIface
95 expectDetails []interface{} // nil elements signify errors
96 }{
97 {
98 desc: "gogo status",
99 makeStatus: func(t *testing.T, code codes.Code, msg string, details []proto.Message) statusIface {
100 s, err := gogostatus.New(code, msg).WithDetails(details...)
101 require.NoError(t, err)
102 return s
103 },
104 fromError: func(err error) statusIface {
105 return gogostatus.Convert(err)
106 },
107 expectDetails: []interface{}{
108 nil, // Protobuf decode fails
109 &errorspb.StringsPayload{Details: []string{"foo", "bar"}}, // gogoproto succeeds
110 nil, // dummy decode fails
111 },
112 },
113 {
114 desc: "grpc status",
115 makeStatus: func(t *testing.T, code codes.Code, msg string, details []proto.Message) statusIface {
116 s := grpcstatus.New(code, msg)
117 for _, detail := range details {
118 var err error
119 s, err = s.WithDetails(protoiface.MessageV1(detail))
120 require.NoError(t, err)
121 }
122 return s
123 },
124 fromError: func(err error) statusIface {
125 return grpcstatus.Convert(err)
126 },
127 expectDetails: []interface{}{
128 // Protobuf succeeds
129 func() interface{} {
130 var st interface{} = grpcstatus.New(codes.Internal, "status").Proto()
131 res := reflect.New(reflect.TypeOf(st).Elem()).Interface()
132 copyPublicFields(res, st)
133 return res
134 }(),
135 nil, // gogoproto decode fails
136 nil, // dummy decode fails
137 },
138 },
139 }
140 for _, tc := range testcases {
141 tc := tc
142 t.Run(tc.desc, func(t *testing.T) {
143 ctx := context.Background()
144
145 // Create a Status, using statusIface to support gRPC and gogo variants.
146 status := tc.makeStatus(t, codes.NotFound, "message", []proto.Message{
147 grpcstatus.New(codes.Internal, "status").Proto(), // standard Protobuf

Callers

nothing calls this directly

Calls 13

EncodeErrorFunction · 0.92
DecodeErrorFunction · 0.92
copyPublicFieldsFunction · 0.85
RunMethod · 0.80
CodeMethod · 0.80
MessageMethod · 0.80
DetailsMethod · 0.80
ErrMethod · 0.80
GetLeafMethod · 0.80
GetWrapperMethod · 0.80
MarshalMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…