github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/common/config/organization_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 config 18 19 import ( 20 "testing" 21 22 mspconfig "github.com/inklabsfoundation/inkchain/common/config/msp" 23 inkchainconfig "github.com/inklabsfoundation/inkchain/core/config" 24 "github.com/inklabsfoundation/inkchain/msp" 25 mspprotos "github.com/inklabsfoundation/inkchain/protos/msp" 26 "github.com/stretchr/testify/assert" 27 ) 28 29 func TestOrganization(t *testing.T) { 30 mspHandler := mspconfig.NewMSPConfigHandler() 31 og := NewOrganizationGroup("testGroup", mspHandler) 32 assert.Equal(t, "testGroup", og.Name(), "Unexpected name returned") 33 _, err := og.NewGroup("testGroup") 34 assert.Error(t, err, "NewGroup should have returned error") 35 36 oc := og.Allocate() 37 _, ok := oc.(*OrganizationConfig) 38 assert.Equal(t, true, ok, "Allocate should have returned an OrganizationConfig") 39 og.OrganizationConfig = oc.(*OrganizationConfig) 40 41 oc.(*OrganizationConfig).Commit() 42 assert.Equal(t, oc, og.OrganizationConfig, "Failed to commit OrganizationConfig") 43 44 mspDir, err := inkchainconfig.GetDevMspDir() 45 assert.NoError(t, err, "Error getting MSP dev directory") 46 mspConf, err := msp.GetVerifyingMspConfig(mspDir, "TestMSP") 47 assert.NoError(t, err, "Error loading MSP config") 48 oc.(*OrganizationConfig).protos.MSP = mspConf 49 mspHandler.BeginConfig(t) 50 err = oc.Validate(t, nil) 51 assert.NoError(t, err, "Validate should not have returned error") 52 assert.Equal(t, "TestMSP", og.MSPID(), "Unexpected MSPID returned") 53 54 og.OrganizationConfig = &OrganizationConfig{ 55 mspID: "ChangeMSP", 56 } 57 err = oc.Validate(t, nil) 58 assert.Error(t, err, "Validate should have returned error for attempt to change MSPID") 59 60 mspConf, err = msp.GetVerifyingMspConfig(mspDir, "") 61 oc.(*OrganizationConfig).protos.MSP = mspConf 62 err = oc.Validate(t, nil) 63 assert.Error(t, err, "Validate should have returned error for empty MSP ID") 64 65 oc.(*OrganizationConfig).protos.MSP = &mspprotos.MSPConfig{} 66 err = oc.Validate(t, nil) 67 assert.Error(t, err, "Validate should have returned error for empty MSPConfig") 68 69 }