(t *testing.T)
| 169 | } |
| 170 | |
| 171 | func (s) TestChainUnaryServerInterceptor(t *testing.T) { |
| 172 | var ( |
| 173 | firstIntKey = ctxKey("firstIntKey") |
| 174 | secondIntKey = ctxKey("secondIntKey") |
| 175 | ) |
| 176 | |
| 177 | firstInt := func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { |
| 178 | if ctx.Value(firstIntKey) != nil { |
| 179 | return nil, status.Errorf(codes.Internal, "first interceptor should not have %v in context", firstIntKey) |
| 180 | } |
| 181 | if ctx.Value(secondIntKey) != nil { |
| 182 | return nil, status.Errorf(codes.Internal, "first interceptor should not have %v in context", secondIntKey) |
| 183 | } |
| 184 | |
| 185 | firstCtx := context.WithValue(ctx, firstIntKey, 0) |
| 186 | resp, err := handler(firstCtx, req) |
| 187 | if err != nil { |
| 188 | return nil, status.Errorf(codes.Internal, "failed to handle request at firstInt") |
| 189 | } |
| 190 | |
| 191 | simpleResp, ok := resp.(*testpb.SimpleResponse) |
| 192 | if !ok { |
| 193 | return nil, status.Errorf(codes.Internal, "failed to get *testpb.SimpleResponse at firstInt") |
| 194 | } |
| 195 | return &testpb.SimpleResponse{ |
| 196 | Payload: &testpb.Payload{ |
| 197 | Type: simpleResp.GetPayload().GetType(), |
| 198 | Body: append(simpleResp.GetPayload().GetBody(), '1'), |
| 199 | }, |
| 200 | }, nil |
| 201 | } |
| 202 | |
| 203 | secondInt := func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { |
| 204 | if ctx.Value(firstIntKey) == nil { |
| 205 | return nil, status.Errorf(codes.Internal, "second interceptor should have %v in context", firstIntKey) |
| 206 | } |
| 207 | if ctx.Value(secondIntKey) != nil { |
| 208 | return nil, status.Errorf(codes.Internal, "second interceptor should not have %v in context", secondIntKey) |
| 209 | } |
| 210 | |
| 211 | secondCtx := context.WithValue(ctx, secondIntKey, 1) |
| 212 | resp, err := handler(secondCtx, req) |
| 213 | if err != nil { |
| 214 | return nil, status.Errorf(codes.Internal, "failed to handle request at secondInt") |
| 215 | } |
| 216 | |
| 217 | simpleResp, ok := resp.(*testpb.SimpleResponse) |
| 218 | if !ok { |
| 219 | return nil, status.Errorf(codes.Internal, "failed to get *testpb.SimpleResponse at secondInt") |
| 220 | } |
| 221 | return &testpb.SimpleResponse{ |
| 222 | Payload: &testpb.Payload{ |
| 223 | Type: simpleResp.GetPayload().GetType(), |
| 224 | Body: append(simpleResp.GetPayload().GetBody(), '2'), |
| 225 | }, |
| 226 | }, nil |
| 227 | } |
| 228 |
nothing calls this directly
no test coverage detected