Skip to content

Commit e234335

Browse files
Fix IsSet() function for sub-sections
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
1 parent fa03f8f commit e234335

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ func (c *configSection) IsSet(key string) bool {
638638
keysMutex.Lock()
639639
defer keysMutex.Unlock()
640640

641-
return viper.IsSet(key)
641+
return viper.IsSet(c.prefixKey(key))
642642
}
643643

644644
// SetupLogging initializes logging

pkg/config/config_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ package config
1919
import (
2020
"context"
2121
"fmt"
22-
"github.com/stretchr/testify/require"
2322
"os"
2423
"path"
2524
"strings"
2625
"testing"
2726
"time"
2827

28+
"github.com/stretchr/testify/require"
29+
2930
"github.com/hyperledger/firefly-common/pkg/fftypes"
3031
"github.com/hyperledger/firefly-common/pkg/i18n"
3132
"github.com/sirupsen/logrus"
@@ -86,10 +87,18 @@ func TestDefaults(t *testing.T) {
8687

8788
func TestValueSet(t *testing.T) {
8889
RootConfigReset()
90+
8991
// keys with default values are not set
92+
AddRootKey("key1")
9093
assert.False(t, IsSet("key1"))
9194
Set("key1", "updatedvalue")
9295
assert.True(t, IsSet("key1"))
96+
97+
section := RootSection("child")
98+
section.AddKnownKey("key1")
99+
assert.False(t, section.IsSet("key1"))
100+
section.Set("key1", "updatedvalue")
101+
assert.True(t, section.IsSet("key1"))
93102
}
94103

95104
func TestSpecificConfigFileOk(t *testing.T) {

0 commit comments

Comments
 (0)