github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/peer/gossip/sa/sa_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package sa
    18  
    19  import (
    20  	"testing"
    21  
    22  	"fmt"
    23  	"os"
    24  
    25  	"github.com/hyperledger/fabric/gossip/api"
    26  	"github.com/hyperledger/fabric/msp/mgmt"
    27  	"github.com/hyperledger/fabric/msp/mgmt/testtools"
    28  	"github.com/stretchr/testify/assert"
    29  )
    30  
    31  func TestMain(m *testing.M) {
    32  	// Setup the MSP manager so that we can sign/verify
    33  	err := msptesttools.LoadMSPSetupForTesting()
    34  	if err != nil {
    35  		fmt.Printf("Failed LoadFakeSetupWithLocalMspAndTestChainMsp [%s]", err)
    36  		os.Exit(-1)
    37  	}
    38  	os.Exit(m.Run())
    39  }
    40  
    41  func TestMspSecurityAdvisor_OrgByPeerIdentity(t *testing.T) {
    42  	id, err := mgmt.GetLocalMSP().GetDefaultSigningIdentity()
    43  	assert.NoError(t, err, "Failed getting local default signing identity")
    44  	identityRaw, err := id.Serialize()
    45  	assert.NoError(t, err, "Failed serializing local default signing identity")
    46  
    47  	advisor := NewSecurityAdvisor()
    48  	orgIdentity := advisor.OrgByPeerIdentity(api.PeerIdentityType(identityRaw))
    49  	assert.NotNil(t, orgIdentity, "Organization for identity must be different from nil")
    50  }