MCPcopy
hub / github.com/spf13/viper / TestDirsSearch

Function TestDirsSearch

viper_test.go:1623–1642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1621}
1622
1623func TestDirsSearch(t *testing.T) {
1624 root, config := initDirs(t)
1625
1626 v := New()
1627 v.SetConfigName(config)
1628 v.SetDefault(`key`, `default`)
1629
1630 entries, err := os.ReadDir(root)
1631 require.NoError(t, err)
1632 for _, e := range entries {
1633 if e.IsDir() {
1634 v.AddConfigPath(filepath.Join(root, e.Name()))
1635 }
1636 }
1637
1638 err = v.ReadInConfig()
1639 require.NoError(t, err)
1640
1641 assert.Equal(t, `value is `+filepath.Base(v.configPaths[0]), v.GetString(`key`))
1642}
1643
1644func TestWrongDirsSearchNotFound(t *testing.T) {
1645 _, config := initDirs(t)

Callers

nothing calls this directly

Calls 8

initDirsFunction · 0.85
NewFunction · 0.85
SetConfigNameMethod · 0.80
SetDefaultMethod · 0.80
AddConfigPathMethod · 0.80
ReadInConfigMethod · 0.80
GetStringMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected