func TestNewPeerEndorserBlocking(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optBlocking := reflect.ValueOf(grpc.WithBlock())
	optBlockingFound := false
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optBlocking.Pointer() {
			optBlockingFound = true
		}
	}
	if !optBlockingFound {
		t.Fatalf("Expected blocking to be found")
	}
}
TestNewPeerEndorserBlocking validates that a client configured with blocking
creates the correct dial options.
package peer
import (
	"crypto/x509"
	"fmt"
	"net"
	"reflect"
	"testing"
	"time"
	"github.com/golang/mock/gomock"
	"github.com/stretchr/testify/assert"
	"google.golang.org/grpc"
	grpcCodes "google.golang.org/grpc/codes"
	"google.golang.org/grpc/keepalive"
	pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
	"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
	"github.com/hyperledger/fabric-sdk-go/api/apiconfig/mocks"
	"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
	"github.com/hyperledger/fabric-sdk-go/pkg/errors/status"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks"
)
const (
	ecertPath   = "../../../test/fixtures/fabricca/tls/certs/client/client_client1.pem"
	peer1URL    = "localhost:7050"
	peer2URL    = "localhost:7054"
	peerURLBad  = "localhost:9999"
	testAddress = "127.0.0.1:0"
)
var kap keepalive.ClientParameters
func TestNewPeerEndorserTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.GoodCert, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optInsecure := reflect.ValueOf(grpc.WithInsecure())
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optInsecure.Pointer() {
			t.Fatalf("TLS enabled - insecure not allowed")
		}
	}
}
func TestNewPeerEndorserMutualTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.GoodCert, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed: %v", err)
	}
	optInsecure := reflect.ValueOf(grpc.WithInsecure())
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optInsecure.Pointer() {
			t.Fatalf("TLS enabled - insecure not allowed")
		}
	}
}
func TestNewPeerEndorserMutualTLSNoClientCerts(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	_, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.GoodCert, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed: %v", err)
	}
}
func TestNewPeerEndorserTLSBadPool(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	_, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.BadCert, "", true, config, kap, false))
	if err == nil {
		t.Fatalf("Peer conn construction should have failed")
	}
}
func TestNewPeerEndorserNoTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpc://0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optInsecure := reflect.ValueOf(grpc.WithInsecure())
	optInsecureFound := false
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optInsecure.Pointer() {
			optInsecureFound = true
		}
	}
	if !optInsecureFound {
		t.Fatalf("Expected insecure to be found")
	}
}