Add tests, expand name.

This commit is contained in:
Mark Fine 2023-07-05 13:25:44 -07:00
parent bb70192ffe
commit 3dca0c3bbf
2 changed files with 51 additions and 3 deletions

View file

@ -1478,11 +1478,11 @@ func (v *Viper) SetEnvKeyReplacer(r *strings.Replacer) {
v.envKeyReplacer = r
}
// SetKeyDelim sets the delimiter used for determining key parts on the viper
// SetKeyDelimiter sets the delimiter used for determining key parts on the viper
// object.
func SetKeyDelim(d string) { v.SetKeyDelim(d) }
func SetKeyDelimiter(d string) { v.SetKeyDelimiter(d) }
func (v *Viper) SetKeyDelim(d string) {
func (v *Viper) SetKeyDelimiter(d string) {
v.keyDelim = d
}

View file

@ -2629,6 +2629,54 @@ func TestKeyDelimiter(t *testing.T) {
assert.Equal(t, expected, actual)
}
func TestSetKeyDelimiter(t *testing.T) {
v := New()
v.SetKeyDelimiter("::")
v.SetConfigType("yaml")
r := strings.NewReader(string(yamlExampleWithDot))
err := v.unmarshalReader(r, v.config)
require.NoError(t, err)
values := map[string]interface{}{
"image": map[string]interface{}{
"repository": "someImage",
"tag": "1.0.0",
},
"ingress": map[string]interface{}{
"annotations": map[string]interface{}{
"traefik.frontend.rule.type": "PathPrefix",
"traefik.ingress.kubernetes.io/ssl-redirect": "true",
},
},
}
v.SetDefault("charts::values", values)
assert.Equal(t, "leather", v.GetString("clothing::jacket"))
assert.Equal(t, "01/02/03", v.GetString("emails::steve@hacker.com::created"))
type config struct {
Charts struct {
Values map[string]interface{}
}
}
expected := config{
Charts: struct {
Values map[string]interface{}
}{
Values: values,
},
}
var actual config
assert.NoError(t, v.Unmarshal(&actual))
assert.Equal(t, expected, actual)
}
var yamlDeepNestedSlices = []byte(`TV:
- title: "The Expanse"
title_i18n: