mirror of
https://github.com/spf13/viper
synced 2024-09-08 00:46:20 +00:00
feat: copy keydelim from parent chart in viper.Sub()
This commit is contained in:
parent
ae564f05cb
commit
864a85aada
1
viper.go
1
viper.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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": [
|
||||
|
|
Loading…
Reference in a new issue