--------------------------------------------------------------------------- startTestServer spins up an in-memory gRPC server with bufconn and returns the mock server, a client, and a cleanup function. ---------------------------------------------------------------------------
(t *testing.T)
| 284 | // --------------------------------------------------------------------------- |
| 285 | |
| 286 | func startTestServer(t *testing.T) (*testServer, listenerrpc.ListenerRPCClient, func()) { |
| 287 | t.Helper() |
| 288 | |
| 289 | srv := newTestServer() |
| 290 | lis := bufconn.Listen(bufSize) |
| 291 | |
| 292 | gs := grpc.NewServer() |
| 293 | listenerrpc.RegisterListenerRPCServer(gs, srv) |
| 294 | |
| 295 | go func() { |
| 296 | if err := gs.Serve(lis); err != nil { |
| 297 | // Ignore errors after cleanup. |
| 298 | } |
| 299 | }() |
| 300 | |
| 301 | dialer := func(ctx context.Context, _ string) (net.Conn, error) { |
| 302 | return lis.DialContext(ctx) |
| 303 | } |
| 304 | |
| 305 | conn, err := grpc.DialContext( |
| 306 | context.Background(), |
| 307 | "bufnet", |
| 308 | grpc.WithContextDialer(dialer), |
| 309 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 310 | ) |
| 311 | if err != nil { |
| 312 | t.Fatalf("failed to dial bufconn: %v", err) |
| 313 | } |
| 314 | |
| 315 | client := listenerrpc.NewListenerRPCClient(conn) |
| 316 | |
| 317 | cleanup := func() { |
| 318 | conn.Close() |
| 319 | gs.Stop() |
| 320 | lis.Close() |
| 321 | } |
| 322 | |
| 323 | return srv, client, cleanup |
| 324 | } |
| 325 | |
| 326 | // --------------------------------------------------------------------------- |
| 327 | // newTestBridgeWithRPC creates a Bridge connected to a real gRPC client, |
no test coverage detected