startMockServer 在 bufconn 上启动 mock,返回 hub + dialer + server stop。
(t *testing.T)
| 116 | |
| 117 | // startMockServer 在 bufconn 上启动 mock,返回 hub + dialer + server stop。 |
| 118 | func startMockServer(t *testing.T) (*mockHub, func(context.Context, string) (net.Conn, error), func()) { |
| 119 | t.Helper() |
| 120 | lis := bufconn.Listen(bufSize) |
| 121 | srv := grpc.NewServer() |
| 122 | hub := newMockHub() |
| 123 | nodev1.RegisterNodeAgentServer(srv, hub) |
| 124 | go func() { _ = srv.Serve(lis) }() |
| 125 | dialer := func(ctx context.Context, _ string) (net.Conn, error) { |
| 126 | return lis.DialContext(ctx) |
| 127 | } |
| 128 | stop := func() { srv.Stop() } |
| 129 | return hub, dialer, stop |
| 130 | } |
| 131 | |
| 132 | // helloProvider 返回一个固定的 hello body。 |
| 133 | func helloProvider() (json.RawMessage, error) { |
no test coverage detected