You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/agent/grpc-external/testutils/server.go

34 lines
567 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package testutils
import (
"net"
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)
type GRPCService interface {
Register(*grpc.Server)
}
func RunTestServer(t *testing.T, services ...GRPCService) net.Addr {
t.Helper()
lis, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
grpcServer := grpc.NewServer()
for _, svc := range services {
svc.Register(grpcServer)
}
go grpcServer.Serve(lis)
t.Cleanup(grpcServer.Stop)
return lis.Addr()
}