func StartBufconnServer()

in internal/search/search_test_helpers.go [20:49]


func StartBufconnServer(t *testing.T, files []*proto.FileMatch, stats *proto.Stats) (*grpc.ClientConn, string) {
	lis := bufconn.Listen(1024 * 1024)
	s := grpc.NewServer()

	mock := &MockZoektGRPCServer{
		files: files,
		stats: stats,
	}
	proto.RegisterWebserverServiceServer(s, mock)

	go func() {
		_ = s.Serve(lis)
	}()

	dialer := func(context.Context, string) (net.Conn, error) {
		return lis.Dial()
	}

	// Generate a unique name and add http:// prefix to make it compatible with parseEndpoint
	endpoint := fmt.Sprintf("http://bufnet-%p", lis)

	// Extract the host part to use as the target for the connection
	hostPart := strings.TrimPrefix(endpoint, "http://")
	hostPart = strings.Split(hostPart, "/")[0]

	conn, err := NewTestGrpcClient(context.Background(), hostPart, dialer)
	require.NoError(t, err)

	return conn, endpoint
}