fix: MapKeys returns empty slice for natively-typed maps
Get() preserves the concrete type of a map[string]T value loaded via Set() or a provider like structs, but MapKeys() only type-asserted map[string]any, so it silently reported no keys for anything else. Read keys via reflection instead so any map with string keys works.
This commit is contained in:
1 parent
15e76cb3d5
commit
9f860a7fd4
3 files changed
+116
-5
No files matched your search
@@ -1533,6 +1533,17 @@ func TestBoolsNativeSlice(t *testing.T) {
|
||||
assert.Equal([]bool{true, false, true}, k.Bools("bools"))
|
||||
}
|
||||
|
||||
func TestMapKeysNativeMap(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
k := koanf.New(delim)
|
||||
assert.NoError(k.Load(confmap.Provider(map[string]any{
|
||||
"ints": map[string]int64{"a": 1, "b": 2},
|
||||
}, "."), nil))
|
||||
|
||||
assert.Equal([]string{"a", "b"}, k.MapKeys("ints"), "map keys mismatch for a natively-typed map")
|
||||
}
|
||||
|
||||
// waitTimeout waits for the waitgroup for the specified max timeout.
|
||||
// Returns true if waiting timed out.
|
||||
func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
|
||||
|
||||
Reference in new issue
Block a user