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)
| 2499 | // `) |
| 2500 | |
| 2501 | func 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 | |
| 2548 | var yamlDeepNestedSlices = []byte(`TV: |
| 2549 | - title: "The Expanse" |
nothing calls this directly
no test coverage detected
searching dependent graphs…