func TestDeprecatedNames(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.NewMockConfig(mockCtrl)
	config.EXPECT().TimeoutOrDefault(apiconfig.Endorser).Return(time.Second * 5)
	peer, err := NewPeer(peer1URL, config)
	if err != nil {
		t.Fatalf("Failed to create NewPeer error(%v)", err)
	}
	if peer.Name() != "" {
		t.Fatalf("Expected empty peer name")
	}
	const peerName = "I am Peer"
	peer.SetName(peerName)
	if peer.Name() != peerName {
		t.Fatalf("Unexpected peer name")
	}
}
TestRoles tests the name certificate getter/setters
package peer
import (
	"encoding/pem"
	"io/ioutil"
	"reflect"
	"testing"
	"time"
	"github.com/golang/mock/gomock"
	"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
	"github.com/hyperledger/fabric-sdk-go/api/apiconfig/mocks"
	fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
	mock_fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient/mocks"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks"
)
func TestDeprecatedNewPeerWithCertNoTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	url := "http://example.com"
	config := mock_apiconfig.NewMockConfig(mockCtrl)
	config.EXPECT().TimeoutOrDefault(apiconfig.Endorser).Return(time.Second * 5)
	p, err := NewPeer(url, config)
	if err != nil {
		t.Fatalf("Expected peer to be constructed")
	}
	if p.URL() != url {
		t.Fatalf("Unexpected peer URL")
	}
}
func TestDeprecatedNewPeerTLSFromCert(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	tlsConfig := apiconfig.TLSConfig{Path: "../../../test/fixtures/fabricca/tls/ca/ca_root.pem"}
	cert, err := tlsConfig.TLSCert()
	if err != nil {
		t.Fatalf("Failed to load cert: %v", err)
	}
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	config.EXPECT().TLSCACertPool(cert).Return(mock_apiconfig.CertPool, nil).AnyTimes()
	url := "grpcs://0.0.0.0:1234"
	_, err = NewPeerTLSFromCert(url, "../../../test/fixtures/fabricca/tls/ca/ca_root.pem", "", config)
	if err != nil {
		t.Fatalf("Expected peer to be constructed, failed with error: %v", err)
	}
}
func TestDeprecatedNewPeerWithCertBadParams(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.NewMockConfig(mockCtrl)
	_, err := NewPeer("", config)
	if err == nil {
		t.Fatalf("Peer should not be constructed - bad params")
	}
}
func TestDeprecatedNewPeerTLSFromCertBad(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	_, err := NewPeerTLSFromCert(url, "", "", config)
	if err == nil {
		t.Fatalf("Expected peer construction to fail")
	}
}
func TestDeprecatedEnrollmentCert(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.NewMockConfig(mockCtrl)
	config.EXPECT().TimeoutOrDefault(apiconfig.Endorser).Return(time.Second * 5)
	peer, err := NewPeer(peer1URL, config)
	if err != nil {
		t.Fatalf("Failed to create NewPeerWithCert error(%v)", err)
	}
	if peer.EnrollmentCertificate() != nil {
		t.Fatalf("Expected empty peer enrollment certs")
	}
	pemBuffer, err := ioutil.ReadFile(ecertPath)
	if err != nil {
		t.Fatalf("ecert fixture missing")
	}
	cert, _ := pem.Decode(pemBuffer)
	peer.SetEnrollmentCertificate(cert)
	fetchedCert := peer.EnrollmentCertificate()
	if !reflect.DeepEqual(cert, fetchedCert) {
		t.Fatalf("Enrollment certificate mismatch")
	}
}
func TestDeprecatedRoles(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.NewMockConfig(mockCtrl)
	config.EXPECT().TimeoutOrDefault(apiconfig.Endorser).Return(time.Second * 5)
	peer, err := NewPeer(peer1URL, config)
	if err != nil {
		t.Fatalf("Failed to create NewPeer error(%v)", err)
	}
	if len(peer.Roles()) != 0 {
		t.Fatalf("Expected empty peer roles")
	}
	roles := []string{"role1", "role2"}
	peer.SetRoles(roles)
	fetchedRoles := peer.Roles()
	if !reflect.DeepEqual(roles, fetchedRoles) {
		t.Fatalf("Unexpected roles")
	}
}