forked from TrueCloudLab/certificates
Use test/bufconn instead of a real listener.
This commit is contained in:
parent
4f9200cc47
commit
b057c6677a
1 changed files with 8 additions and 7 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -30,6 +31,7 @@ import (
|
||||||
pb "google.golang.org/genproto/googleapis/cloud/security/privateca/v1beta1"
|
pb "google.golang.org/genproto/googleapis/cloud/security/privateca/v1beta1"
|
||||||
longrunningpb "google.golang.org/genproto/googleapis/longrunning"
|
longrunningpb "google.golang.org/genproto/googleapis/longrunning"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/test/bufconn"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -790,21 +792,20 @@ func TestCloudCAS_CreateCertificateAuthority(t *testing.T) {
|
||||||
mos := NewMockOperationsServer(mosCtrl)
|
mos := NewMockOperationsServer(mosCtrl)
|
||||||
|
|
||||||
// Create operation server
|
// Create operation server
|
||||||
lis, err := net.Listen("tcp", "localhost:0")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srv := grpc.NewServer()
|
srv := grpc.NewServer()
|
||||||
longrunningpb.RegisterOperationsServer(srv, mos)
|
longrunningpb.RegisterOperationsServer(srv, mos)
|
||||||
|
|
||||||
|
lis := bufconn.Listen(2)
|
||||||
go srv.Serve(lis)
|
go srv.Serve(lis)
|
||||||
defer srv.Stop()
|
defer srv.Stop()
|
||||||
|
|
||||||
// Create fake privateca client
|
// Create fake privateca client
|
||||||
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
|
conn, err := grpc.DialContext(context.Background(), "", grpc.WithInsecure(),
|
||||||
|
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
|
||||||
|
return lis.Dial()
|
||||||
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := lroauto.NewOperationsClient(context.Background(), option.WithGRPCConn(conn))
|
client, err := lroauto.NewOperationsClient(context.Background(), option.WithGRPCConn(conn))
|
||||||
|
|
Loading…
Reference in a new issue