github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/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 ) 25 26 func TestGetManagerForChains(t *testing.T) { 27 // MSPManager for channel does not exist prior to this call 28 mspMgr1 := GetManagerForChain("test") 29 // ensure MSPManager is set 30 if mspMgr1 == nil { 31 t.FailNow() 32 } 33 34 // MSPManager for channel now exists 35 mspMgr2 := GetManagerForChain("test") 36 // ensure MSPManager returned matches the first result 37 if mspMgr2 != mspMgr1 { 38 t.FailNow() 39 } 40 } 41 42 func TestGetManagerForChains_usingMSPConfigHandlers(t *testing.T) { 43 XXXSetMSPManager("test", &configvaluesmsp.MSPConfigHandler{MSPManager: nil}) 44 msp1 := GetManagerForChain("test") 45 // return value should be nil because the MSPManager was not initialized 46 if msp1 != nil { 47 t.Fatal("MSPManager should have been nil") 48 } 49 50 XXXSetMSPManager("foo", &configvaluesmsp.MSPConfigHandler{MSPManager: msp.NewMSPManager()}) 51 msp2 := GetManagerForChain("foo") 52 // return value should be set because the MSPManager was initialized 53 if msp2 == nil { 54 t.FailNow() 55 } 56 }