github.com/ewagmig/fabric@v2.1.1+incompatible/gossip/state/config_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package state_test 8 9 import ( 10 "testing" 11 "time" 12 13 "github.com/hyperledger/fabric/gossip/state" 14 "github.com/stretchr/testify/assert" 15 16 "github.com/spf13/viper" 17 ) 18 19 func TestGlobalConfig(t *testing.T) { 20 viper.Reset() 21 viper.Set("peer.gossip.state.checkInterval", "1s") 22 viper.Set("peer.gossip.state.responseTimeout", "2s") 23 viper.Set("peer.gossip.state.batchSize", 3) 24 viper.Set("peer.gossip.state.maxRetries", 4) 25 viper.Set("peer.gossip.state.blockBufferSize", 5) 26 viper.Set("peer.gossip.state.channelSize", 6) 27 viper.Set("peer.gossip.state.enabled", false) 28 29 coreConfig := state.GlobalConfig() 30 31 expectedConfig := &state.StateConfig{ 32 StateCheckInterval: time.Second, 33 StateResponseTimeout: 2 * time.Second, 34 StateBatchSize: uint64(3), 35 StateMaxRetries: 4, 36 StateBlockBufferSize: 5, 37 StateChannelSize: 6, 38 StateEnabled: false, 39 } 40 41 assert.Equal(t, expectedConfig, coreConfig) 42 } 43 44 func TestGlobalConfigDefaults(t *testing.T) { 45 viper.Reset() 46 47 coreConfig := state.GlobalConfig() 48 49 expectedConfig := &state.StateConfig{ 50 StateCheckInterval: 10 * time.Second, 51 StateResponseTimeout: 3 * time.Second, 52 StateBatchSize: uint64(10), 53 StateMaxRetries: 3, 54 StateBlockBufferSize: 100, 55 StateChannelSize: 100, 56 StateEnabled: true, 57 } 58 59 assert.Equal(t, expectedConfig, coreConfig) 60 }