MCPcopy
hub / github.com/grpc/grpc-go / TestTapStatusDetails

Method TestTapStatusDetails

test/end2end_test.go:2159–2201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2157}
2158
2159func (s) TestTapStatusDetails(t *testing.T) {
2160 tapHandler := func(context.Context, *tap.Info) (context.Context, error) {
2161 // Return error with details for all RPCs.
2162 wantDetails := &testpb.Empty{}
2163 st := status.New(codes.ResourceExhausted, "rate limit exceeded")
2164 st, err := st.WithDetails(wantDetails)
2165 if err != nil {
2166 t.Errorf("status.WithDetails() failed: %v", err)
2167 }
2168 return nil, st.Err()
2169 }
2170
2171 ss := stubserver.StartTestService(t, nil, grpc.InTapHandle(tapHandler))
2172 defer ss.Stop()
2173
2174 if err := ss.StartClient(); err != nil {
2175 t.Fatalf("ss.StartClient() failed: %v", err)
2176 }
2177
2178 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
2179 defer cancel()
2180
2181 _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{})
2182 if err == nil {
2183 t.Fatal("EmptyCall() succeeded; want error")
2184 }
2185
2186 gotStatus := status.Convert(err)
2187 if gotStatus.Code() != codes.ResourceExhausted {
2188 t.Errorf("EmptyCall() returned code %v; want %v", gotStatus.Code(), codes.ResourceExhausted)
2189 }
2190 if gotStatus.Message() != "rate limit exceeded" {
2191 t.Errorf("EmptyCall() returned message %q; want %q", gotStatus.Message(), "rate limit exceeded")
2192 }
2193
2194 details := gotStatus.Details()
2195 if len(details) != 1 {
2196 t.Fatalf("EmptyCall() returned %d details; want 1", len(details))
2197 }
2198 if _, ok := details[0].(*testpb.Empty); !ok {
2199 t.Fatalf("EmptyCall() returned detail type %T; want *testpb.Empty", details[0])
2200 }
2201}
2202
2203func (s) TestEmptyUnaryWithUserAgent(t *testing.T) {
2204 for _, e := range listTestEnv() {

Callers

nothing calls this directly

Calls 13

StartTestServiceFunction · 0.92
InTapHandleFunction · 0.92
WithDetailsMethod · 0.80
ErrMethod · 0.80
StartClientMethod · 0.80
CodeMethod · 0.80
MessageMethod · 0.80
DetailsMethod · 0.80
ErrorfMethod · 0.65
StopMethod · 0.65
FatalfMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected