MCPcopy
hub / github.com/knadh/koanf / TestSlices

Function TestSlices

tests/koanf_test.go:1279–1307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1277}
1278
1279func TestSlices(t *testing.T) {
1280 assert := assert.New(t)
1281
1282 // Load a slice of confmaps [{}, {}].
1283 var mp map[string]any
1284 err := encjson.Unmarshal([]byte(`{
1285 "parent": [
1286 {"value": 1, "sub": {"value": "1"}},
1287 {"value": 2, "sub": {"value": "2"}}
1288 ],
1289 "another": "123"
1290 }`), &mp)
1291 assert.NoError(err, "error marshalling test payload")
1292 k := koanf.New(delim)
1293 assert.NoError(k.Load(confmap.Provider(mp, "."), nil))
1294
1295 assert.Empty(k.Slices("x"))
1296 assert.Empty(k.Slices("parent.value"))
1297 assert.Empty(k.Slices("parent.value.sub"))
1298
1299 slices := k.Slices("parent")
1300 assert.NotNil(slices, "got nil slice of confmap")
1301 assert.NotEmpty(slices, "got empty confmap slice")
1302
1303 for i, s := range slices {
1304 assert.Equal(s.Int("value"), i+1)
1305 assert.Equal(s.String("sub.value"), fmt.Sprintf("%d", i+1))
1306 }
1307}
1308
1309func TestGetTypes(t *testing.T) {
1310 assert := assert.New(t)

Callers

nothing calls this directly

Calls 5

LoadMethod · 0.80
SlicesMethod · 0.80
IntMethod · 0.80
StringMethod · 0.80
UnmarshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…