This repository was archived by the owner on Apr 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -218,22 +218,27 @@ func (c *ChannelConfig) resolveOptsFromConfig(ctx context.Client) error {
218218 }
219219
220220 if c .opts .MaxTargets == 0 {
221- c .opts .MaxTargets = chSdkCfg .Policies .QueryChannelConfig .MaxTargets
221+ if chSdkCfg != nil && & chSdkCfg .Policies != nil && & chSdkCfg .Policies .QueryChannelConfig != nil {
222+ c .opts .MaxTargets = chSdkCfg .Policies .QueryChannelConfig .MaxTargets
223+ }
222224 if c .opts .MaxTargets == 0 {
223225 c .opts .MaxTargets = defaultMaxTargets
224226 }
225227 }
226228
227229 if c .opts .MinResponses == 0 {
228- c .opts .MinResponses = chSdkCfg .Policies .QueryChannelConfig .MinResponses
230+ if chSdkCfg != nil && & chSdkCfg .Policies != nil && & chSdkCfg .Policies .QueryChannelConfig != nil {
231+ c .opts .MinResponses = chSdkCfg .Policies .QueryChannelConfig .MinResponses
232+ }
229233 if c .opts .MinResponses == 0 {
230234 c .opts .MinResponses = defaultMinResponses
231235 }
232236 }
233237
234238 if c .opts .RetryOpts .RetryableCodes == nil {
235- c .opts .RetryOpts = chSdkCfg .Policies .QueryChannelConfig .RetryOpts
236-
239+ if chSdkCfg != nil && & chSdkCfg .Policies != nil && & chSdkCfg .Policies .QueryChannelConfig != nil {
240+ c .opts .RetryOpts = chSdkCfg .Policies .QueryChannelConfig .RetryOpts
241+ }
237242 if c .opts .RetryOpts .Attempts == 0 {
238243 c .opts .RetryOpts .Attempts = retry .DefaultAttempts
239244 }
Original file line number Diff line number Diff line change @@ -222,6 +222,26 @@ func TestResolveOptsFromConfig(t *testing.T) {
222222 assert .False (t , mockConfig .called , "config.ChannelConfig() should not be used by resolve opts function once opts are loaded" )
223223}
224224
225+ func TestResolveOptsDefaultValues (t * testing.T ) {
226+ user := mspmocks .NewMockSigningIdentity ("test" , "test" )
227+ ctx := mocks .NewMockContext (user )
228+
229+ mockConfig := & customMockConfig {MockConfig : & mocks.MockConfig {}, chConfig : nil }
230+ ctx .SetConfig (mockConfig )
231+
232+ channelConfig , err := New (channelID , WithPeers ([]fab.Peer {}))
233+ if err != nil {
234+ t .Fatal ("Failed to create channel config" )
235+ }
236+ err = channelConfig .resolveOptsFromConfig (ctx )
237+ if err != nil {
238+ t .Fatal ("Failed to resolve opts from config" )
239+ }
240+ assert .True (t , channelConfig .opts .MaxTargets == 2 , "supposed to be loaded once opts resolved from config" )
241+ assert .True (t , channelConfig .opts .MinResponses == 1 , "supposed to be loaded once opts resolved from config" )
242+ assert .True (t , channelConfig .opts .RetryOpts .RetryableCodes != nil , "supposed to be loaded once opts resolved from config" )
243+ }
244+
225245func setupTestContext () context.Client {
226246 user := mspmocks .NewMockSigningIdentity ("test" , "test" )
227247 ctx := mocks .NewMockContext (user )
You can’t perform that action at this time.
0 commit comments