Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 8a88832

Browse files
author
Firas Qutishat
committed
[FAB-9095] Panic when no channel policies defined
Change-Id: Iaae22889ee0991975ad6c33888998a5a5ae1f687 Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
1 parent 02c85b3 commit 8a88832

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

pkg/fab/chconfig/chconfig.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

pkg/fab/chconfig/chconfig_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
225245
func setupTestContext() context.Client {
226246
user := mspmocks.NewMockSigningIdentity("test", "test")
227247
ctx := mocks.NewMockContext(user)

0 commit comments

Comments
 (0)