Skip to content

Commit 556d18b

Browse files
authored
fix: Fix incorrectly initialized clone with regards to env vars (#388)
1 parent 4b6d93a commit 556d18b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/configuration/configuration.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,13 @@ func (ev *extendedViper) Clone() Configuration {
279279
defer ev.mutex.RUnlock()
280280

281281
// manually clone the Configuration instance
282-
var clone Configuration
282+
options := []Opts{}
283283
if ev.configType == jsonFile {
284284
configFileUsed := ev.viper.ConfigFileUsed()
285-
clone = NewFromFiles(configFileUsed)
286-
} else {
287-
clone = NewInMemory()
285+
options = append(options, WithFiles(configFileUsed))
288286
}
289287

288+
clone := NewWithOpts(options...)
290289
clone.SetStorage(ev.storage)
291290
keys := ev.viper.AllKeys()
292291
for i := range keys {

pkg/configuration/configuration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func Test_ConfigurationClone(t *testing.T) {
291291
flagset.Bool("debug", true, "debugging")
292292
flagset.Float64("size", 10, "size")
293293

294-
config := NewFromFiles(TEST_FILENAME)
294+
config := NewWithOpts(WithFiles(TEST_FILENAME))
295295
err := config.AddFlagSet(flagset)
296296
assert.NoError(t, err)
297297

@@ -352,6 +352,7 @@ func Test_ConfigurationClone(t *testing.T) {
352352

353353
// we assume that a cloned configuration uses the same storage object. Just the pointer is cloned.
354354
assert.Equal(t, config.(*extendedViper).storage, clonedConfig.(*extendedViper).storage)
355+
assert.Equal(t, config.(*extendedViper).automaticEnvEnabled, clonedConfig.(*extendedViper).automaticEnvEnabled)
355356

356357
cleanupConfigstore(t)
357358
}

0 commit comments

Comments
 (0)