TestSpec_* functions derive from the importinpututil README.md specification. Each test maps to a documented section of the package contract and is written against the public API only — not against implementation internals. TestSpec_PublicAPI_ResolvePathValue validates the documented behavior of Res
(t *testing.T)
| 23 | // - Returns (value, true) on success. |
| 24 | // - Returns (nil, false) when the key is absent or the dotted path cannot be traversed. |
| 25 | func TestSpec_PublicAPI_ResolvePathValue(t *testing.T) { |
| 26 | inputs := map[string]any{ |
| 27 | "count": 42, |
| 28 | "config": map[string]any{"apiKey": "secret"}, |
| 29 | } |
| 30 | |
| 31 | tests := []struct { |
| 32 | name string |
| 33 | inputPath string |
| 34 | wantValue any |
| 35 | wantOK bool |
| 36 | }{ |
| 37 | {name: "documented: top-level key", inputPath: "count", wantValue: 42, wantOK: true}, |
| 38 | {name: "documented: dotted sub-key", inputPath: "config.apiKey", wantValue: "secret", wantOK: true}, |
| 39 | {name: "documented: missing top-level key", inputPath: "missing", wantValue: nil, wantOK: false}, |
| 40 | } |
| 41 | |
| 42 | for _, tt := range tests { |
| 43 | t.Run(tt.name, func(t *testing.T) { |
| 44 | value, ok := importinpututil.ResolvePathValue(inputs, tt.inputPath) |
| 45 | assert.Equal(t, tt.wantOK, ok, "ResolvePathValue(%q) ok mismatch for: %s", tt.inputPath, tt.name) |
| 46 | assert.Equal(t, tt.wantValue, value, "ResolvePathValue(%q) value mismatch for: %s", tt.inputPath, tt.name) |
| 47 | }) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // TestSpec_PublicAPI_ResolvePathValue_DottedPathTraversalFailure validates the |
| 52 | // documented "(nil, false)" result when a dotted path cannot be traversed. |
nothing calls this directly
no test coverage detected