setupTestServer set up the gRPC server for AggregatedDiscoveryService. It creates an instance of testServer that returns the provided response from the StreamAggregatedResources() handler and registers it with a gRPC server.
(t *testing.T, response *v3discoverypb.DiscoveryResponse)
| 66 | // creates an instance of testServer that returns the provided response from |
| 67 | // the StreamAggregatedResources() handler and registers it with a gRPC server. |
| 68 | func setupTestServer(t *testing.T, response *v3discoverypb.DiscoveryResponse) *testServer { |
| 69 | t.Helper() |
| 70 | |
| 71 | lis, err := net.Listen("tcp", "localhost:0") |
| 72 | if err != nil { |
| 73 | t.Fatalf("Failed to listen on localhost:0: %v", err) |
| 74 | } |
| 75 | ts := &testServer{ |
| 76 | requestChan: make(chan *v3discoverypb.DiscoveryRequest), |
| 77 | address: lis.Addr().String(), |
| 78 | response: response, |
| 79 | } |
| 80 | |
| 81 | s := grpc.NewServer() |
| 82 | |
| 83 | v3discoverygrpc.RegisterAggregatedDiscoveryServiceServer(s, ts) |
| 84 | go s.Serve(lis) |
| 85 | t.Cleanup(s.Stop) |
| 86 | |
| 87 | return ts |
| 88 | } |
| 89 | |
| 90 | // StreamAggregatedResources handles bidirectional streaming of |
| 91 | // DiscoveryRequest and DiscoveryResponse. It waits for a message from the |
no test coverage detected