(t *testing.T)
| 286 | } |
| 287 | |
| 288 | func (s) TestChainOnBaseUnaryServerInterceptor(t *testing.T) { |
| 289 | baseIntKey := ctxKey("baseIntKey") |
| 290 | |
| 291 | baseInt := func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { |
| 292 | if ctx.Value(baseIntKey) != nil { |
| 293 | return nil, status.Errorf(codes.Internal, "base interceptor should not have %v in context", baseIntKey) |
| 294 | } |
| 295 | |
| 296 | baseCtx := context.WithValue(ctx, baseIntKey, 1) |
| 297 | return handler(baseCtx, req) |
| 298 | } |
| 299 | |
| 300 | chainInt := func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { |
| 301 | if ctx.Value(baseIntKey) == nil { |
| 302 | return nil, status.Errorf(codes.Internal, "chain interceptor should have %v in context", baseIntKey) |
| 303 | } |
| 304 | |
| 305 | return handler(ctx, req) |
| 306 | } |
| 307 | |
| 308 | sopts := []grpc.ServerOption{ |
| 309 | grpc.UnaryInterceptor(baseInt), |
| 310 | grpc.ChainUnaryInterceptor(chainInt), |
| 311 | } |
| 312 | |
| 313 | ss := &stubserver.StubServer{ |
| 314 | EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { |
| 315 | return &testpb.Empty{}, nil |
| 316 | }, |
| 317 | } |
| 318 | if err := ss.Start(sopts); err != nil { |
| 319 | t.Fatalf("Error starting endpoint server: %v", err) |
| 320 | } |
| 321 | defer ss.Stop() |
| 322 | |
| 323 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 324 | defer cancel() |
| 325 | resp, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}) |
| 326 | if s, ok := status.FromError(err); !ok || s.Code() != codes.OK { |
| 327 | t.Fatalf("ss.Client.EmptyCall(ctx, _) = %v, %v; want nil, <status with Code()=OK>", resp, err) |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | func (s) TestChainStreamServerInterceptor(t *testing.T) { |
| 332 | callCounts := make([]atomic.Int32, 4) |
nothing calls this directly
no test coverage detected