feat: copy keydelim from parent chart in viper.Sub()

This commit is contained in:
alex.lew 2024-07-22 20:14:28 +00:00 committed by Márk Sági-Kazár
parent ae564f05cb
commit 864a85aada
2 changed files with 12 additions and 0 deletions

View file

@ -774,6 +774,7 @@ func (v *Viper) Sub(key string) *Viper {
subv.automaticEnvApplied = v.automaticEnvApplied
subv.envPrefix = v.envPrefix
subv.envKeyReplacer = v.envKeyReplacer
subv.keyDelim = v.keyDelim
subv.config = cast.ToStringMap(data)
return subv
}

View file

@ -1681,6 +1681,17 @@ func TestSub(t *testing.T) {
assert.Equal(t, []string{"clothing", "pants"}, subv.parents)
}
func TestSubWithKeyDelimiter(t *testing.T) {
v := NewWithOptions(KeyDelimiter("::"))
v.SetConfigType("yaml")
r := strings.NewReader(string(yamlExampleWithDot))
err := v.unmarshalReader(r, v.config)
require.NoError(t, err)
subv := v.Sub("emails")
assert.Equal(t, "01/02/03", subv.Get("steve@hacker.com::created"))
}
var jsonWriteExpected = []byte(`{
"batters": {
"batter": [