github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/msp/mgmt/mgmt_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 mgmt
    18  
    19  import (
    20  	"testing"
    21  
    22  	configvaluesmsp "github.com/hyperledger/fabric/common/config/msp"
    23  	"github.com/hyperledger/fabric/msp"
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestGetManagerForChains(t *testing.T) {
    28  	// MSPManager for channel does not exist prior to this call
    29  	mspMgr1 := GetManagerForChain("test")
    30  	// ensure MSPManager is set
    31  	if mspMgr1 == nil {
    32  		t.FailNow()
    33  	}
    34  
    35  	// MSPManager for channel now exists
    36  	mspMgr2 := GetManagerForChain("test")
    37  	// ensure MSPManager returned matches the first result
    38  	if mspMgr2 != mspMgr1 {
    39  		t.FailNow()
    40  	}
    41  }
    42  
    43  func TestGetManagerForChains_usingMSPConfigHandlers(t *testing.T) {
    44  	XXXSetMSPManager("test", &configvaluesmsp.MSPConfigHandler{MSPManager: nil})
    45  	msp1 := GetManagerForChain("test")
    46  	// return value should be nil because the MSPManager was not initialized
    47  	if msp1 != nil {
    48  		t.Fatal("MSPManager should have been nil")
    49  	}
    50  
    51  	XXXSetMSPManager("foo", &configvaluesmsp.MSPConfigHandler{MSPManager: msp.NewMSPManager()})
    52  	msp2 := GetManagerForChain("foo")
    53  	// return value should be set because the MSPManager was initialized
    54  	if msp2 == nil {
    55  		t.FailNow()
    56  	}
    57  }
    58  
    59  func TestGetIdentityDeserializer(t *testing.T) {
    60  	XXXSetMSPManager("baz", &configvaluesmsp.MSPConfigHandler{MSPManager: msp.NewMSPManager()})
    61  	ids := GetIdentityDeserializer("baz")
    62  	assert.NotNil(t, ids)
    63  	ids = GetIdentityDeserializer("")
    64  	assert.NotNil(t, ids)
    65  }
    66  
    67  func TestGetLocalSigningIdentityOrPanic(t *testing.T) {
    68  	sid := GetLocalSigningIdentityOrPanic()
    69  	assert.NotNil(t, sid)
    70  }