(t *testing.T)
| 3 | import "testing" |
| 4 | |
| 5 | func TestResolvePathValue(t *testing.T) { |
| 6 | inputs := map[string]any{ |
| 7 | "name": "alice", |
| 8 | "config": map[string]any{ |
| 9 | "token": "abc", |
| 10 | }, |
| 11 | "bad": "not-map", |
| 12 | } |
| 13 | |
| 14 | tests := []struct { |
| 15 | name string |
| 16 | path string |
| 17 | want any |
| 18 | found bool |
| 19 | }{ |
| 20 | {name: "top level", path: "name", want: "alice", found: true}, |
| 21 | {name: "dotted path", path: "config.token", want: "abc", found: true}, |
| 22 | {name: "missing top level", path: "missing", found: false}, |
| 23 | {name: "missing dotted key", path: "config.missing", found: false}, |
| 24 | {name: "dotted non map", path: "bad.token", found: false}, |
| 25 | } |
| 26 | |
| 27 | for _, tt := range tests { |
| 28 | t.Run(tt.name, func(t *testing.T) { |
| 29 | got, ok := ResolvePathValue(inputs, tt.path) |
| 30 | if ok != tt.found { |
| 31 | t.Fatalf("ResolvePathValue(%q) found = %v, want %v", tt.path, ok, tt.found) |
| 32 | } |
| 33 | if ok && got != tt.want { |
| 34 | t.Fatalf("ResolvePathValue(%q) = %#v, want %#v", tt.path, got, tt.want) |
| 35 | } |
| 36 | }) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func TestFormatResolvedValue(t *testing.T) { |
| 41 | tests := []struct { |
nothing calls this directly
no test coverage detected