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

Commit 530eb84

Browse files
committed
[FABG-701] fix: use variable defaultVal, not const true
Change-Id: I20a017042d55b2bd08699c3ae0d185469b5095e3 Signed-off-by: ping40 <norberthu30@gmail.com>
1 parent fa73e44 commit 530eb84

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

pkg/fab/endpointconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ func peerChannelConfigHookFunc() mapstructure.DecodeHookFunc {
15261526
func setDefault(dataMap map[string]interface{}, key string, defaultVal bool) {
15271527
_, ok := dataMap[key]
15281528
if !ok {
1529-
dataMap[key] = true
1529+
dataMap[key] = defaultVal
15301530
}
15311531
}
15321532

pkg/fab/endpointconfig_test.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ package fab
99
import (
1010
"crypto/tls"
1111
"crypto/x509"
12-
"testing"
13-
14-
"github.com/stretchr/testify/require"
15-
16-
"os"
17-
12+
"encoding/pem"
1813
"fmt"
19-
20-
"time"
21-
22-
"strings"
23-
14+
"os"
2415
"reflect"
16+
"strings"
17+
"testing"
18+
"time"
2519

26-
"encoding/pem"
20+
"github.com/pkg/errors"
21+
"github.com/spf13/viper"
22+
"github.com/stretchr/testify/assert"
23+
"github.com/stretchr/testify/require"
2724

2825
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
2926
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
@@ -33,9 +30,6 @@ import (
3330
"github.com/hyperledger/fabric-sdk-go/pkg/core/mocks"
3431
"github.com/hyperledger/fabric-sdk-go/pkg/fab/comm"
3532
"github.com/hyperledger/fabric-sdk-go/pkg/util/pathvar"
36-
"github.com/pkg/errors"
37-
"github.com/spf13/viper"
38-
"github.com/stretchr/testify/assert"
3933
)
4034

4135
const (
@@ -1495,3 +1489,24 @@ func TestChannelConfigQueryDiscovery(t *testing.T) {
14951489
assert.Equal(t, 4, chConfig.Policies.QueryChannelConfig.QueryDiscovery)
14961490

14971491
}
1492+
1493+
func TestSetDefault(t *testing.T) {
1494+
dataMap := make(map[string]interface{})
1495+
key1 := "key1"
1496+
key2 := "key2"
1497+
key3 := "key3"
1498+
defaultVal1 := true
1499+
defaultVal2 := false
1500+
key3Val := true
1501+
1502+
setDefault(dataMap, key1, defaultVal1)
1503+
assert.Equal(t, defaultVal1, dataMap[key1])
1504+
1505+
setDefault(dataMap, key2, defaultVal2)
1506+
assert.Equal(t, defaultVal2, dataMap[key2])
1507+
1508+
// setDefault makes no effects
1509+
dataMap[key3] = key3Val
1510+
setDefault(dataMap, key3, !key3Val)
1511+
assert.Equal(t, key3Val, dataMap[key3])
1512+
}

0 commit comments

Comments
 (0)