Skip to content

Commit eabbc68

Browse files
committed
Fix file path lookup
1 parent 5ad4bc0 commit eabbc68

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ func absPathify(inPath string) string {
114114
return ""
115115
}
116116

117-
// Check if File / Directory Exists
117+
// Check if file Exists
118118
func exists(fs afero.Fs, path string) (bool, error) {
119-
_, err := fs.Stat(path)
119+
stat, err := fs.Stat(path)
120120
if err == nil {
121-
return true, nil
121+
return !stat.IsDir(), nil
122122
}
123123
if os.IsNotExist(err) {
124124
return false, nil

viper_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,26 @@ func TestSearchInPath(t *testing.T) {
323323
assert.NoError(t, err)
324324
}
325325

326+
func TestSearchInPath_FilesOnly(t *testing.T) {
327+
fs := afero.NewMemMapFs()
328+
329+
err := fs.Mkdir("/tmp/config", 0777)
330+
require.NoError(t, err)
331+
332+
_, err = fs.Create("/tmp/config/config.yaml")
333+
require.NoError(t, err)
334+
335+
v := New()
336+
337+
v.SetFs(fs)
338+
v.AddConfigPath("/tmp")
339+
v.AddConfigPath("/tmp/config")
340+
341+
filename, err := v.getConfigFile()
342+
assert.Equal(t, "/tmp/config/config.yaml", filename)
343+
assert.NoError(t, err)
344+
}
345+
326346
func TestDefault(t *testing.T) {
327347
SetDefault("age", 45)
328348
assert.Equal(t, 45, Get("age"))

0 commit comments

Comments
 (0)