github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/common/config/root_test.go (about) 1 /* 2 Copyright IBM Corp. 2016 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 "github.com/inklabsfoundation/inkchain/common/config/msp" 23 24 logging "github.com/op/go-logging" 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func init() { 29 logging.SetLevel(logging.DEBUG, "") 30 } 31 32 func TestRoot(t *testing.T) { 33 r := NewRoot(&msp.MSPConfigHandler{}) 34 appGroup := &ApplicationGroup{} 35 ordererGroup := &OrdererGroup{} 36 consortiumsGroup := &ConsortiumsGroup{} 37 r.Channel().appConfig = appGroup 38 r.Channel().ordererConfig = ordererGroup 39 r.Channel().consortiumsConfig = consortiumsGroup 40 41 assert.Equal(t, appGroup, r.Application(), "Failed to return correct application group") 42 assert.Equal(t, ordererGroup, r.Orderer(), "Failed to return correct orderer group") 43 assert.Equal(t, consortiumsGroup, r.Consortiums(), "Failed to return correct consortiums group") 44 } 45 46 func TestBeginBadRoot(t *testing.T) { 47 r := NewRoot(&msp.MSPConfigHandler{}) 48 49 _, _, err := r.BeginValueProposals(t, []string{ChannelGroupKey, ChannelGroupKey}) 50 assert.Error(t, err, "Only one root element allowed") 51 52 _, _, err = r.BeginValueProposals(t, []string{"foo"}) 53 assert.Error(t, err, "Non %s group not allowed", ChannelGroupKey) 54 } 55 56 func TestProposeValue(t *testing.T) { 57 r := NewRoot(msp.NewMSPConfigHandler()) 58 59 vd, _, err := r.BeginValueProposals(t, []string{ChannelGroupKey}) 60 assert.NoError(t, err) 61 62 _, err = vd.Deserialize("foo", nil) 63 assert.Error(t, err, "ProposeValue should return error") 64 }