MCPcopy
hub / github.com/spf13/viper / TestKeyDelimiter

Function TestKeyDelimiter

viper_test.go:2501–2546  ·  view source on GitHub ↗

var yamlExampleWithDot = []byte(`Hacker: true name: steve hobbies: - skateboarding - snowboarding - go clothing: jacket: leather trousers: denim pants: size: large age: 35 eyes : brown beard: true emails: steve@hacker.com: created: 01/02/03 active: true `)

(t *testing.T)

Source from the content-addressed store, hash-verified

2499// `)
2500
2501func TestKeyDelimiter(t *testing.T) {
2502 v := NewWithOptions(KeyDelimiter("::"))
2503 v.SetConfigType("yaml")
2504 r := strings.NewReader(string(yamlExampleWithDot))
2505
2506 err := v.unmarshalReader(r, v.config)
2507 require.NoError(t, err)
2508
2509 values := map[string]any{
2510 "image": map[string]any{
2511 "repository": "someImage",
2512 "tag": "1.0.0",
2513 },
2514 "ingress": map[string]any{
2515 "annotations": map[string]any{
2516 "traefik.frontend.rule.type": "PathPrefix",
2517 "traefik.ingress.kubernetes.io/ssl-redirect": "true",
2518 },
2519 },
2520 }
2521
2522 v.SetDefault("charts::values", values)
2523
2524 assert.Equal(t, "leather", v.GetString("clothing::jacket"))
2525 assert.Equal(t, "01/02/03", v.GetString("emails::steve@hacker.com::created"))
2526
2527 type config struct {
2528 Charts struct {
2529 Values map[string]any
2530 }
2531 }
2532
2533 expected := config{
2534 Charts: struct {
2535 Values map[string]any
2536 }{
2537 Values: values,
2538 },
2539 }
2540
2541 var actual config
2542
2543 require.NoError(t, v.Unmarshal(&actual))
2544
2545 assert.Equal(t, expected, actual)
2546}
2547
2548var yamlDeepNestedSlices = []byte(`TV:
2549- title: "The Expanse"

Callers

nothing calls this directly

Calls 7

NewWithOptionsFunction · 0.85
KeyDelimiterFunction · 0.85
SetConfigTypeMethod · 0.80
unmarshalReaderMethod · 0.80
SetDefaultMethod · 0.80
GetStringMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…