diff --git a/viper.go b/viper.go index 0699c4c..578011f 100644 --- a/viper.go +++ b/viper.go @@ -1863,6 +1863,10 @@ func (v *Viper) getConfigFile() (string, error) { func (v *Viper) searchInPath(in string) (filename string) { jww.DEBUG.Println("Searching for config in ", in) + if b, _ := exists(v.fs, filepath.Join(in, v.configName)); b { + return filepath.Join(in, v.configName) + } + for _, ext := range SupportedExts { jww.DEBUG.Println("Checking for", filepath.Join(in, v.configName+"."+ext)) if b, _ := exists(v.fs, filepath.Join(in, v.configName+"."+ext)); b { diff --git a/viper_test.go b/viper_test.go index c40c971..e8f8184 100644 --- a/viper_test.go +++ b/viper_test.go @@ -14,6 +14,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "reflect" "runtime" "sort" @@ -273,6 +274,22 @@ func TestBasics(t *testing.T) { assert.NoError(t, err) } +func TestSearchInPath(t *testing.T) { + filename := ".dotfilenoext" + path := "/tmp" + file := filepath.Join(path, filename) + SetConfigName(filename) + AddConfigPath(path) + _, createErr := v.fs.Create(file) + defer func() { + _ = v.fs.Remove(file) + }() + assert.NoError(t, createErr) + filename, err := v.getConfigFile() + assert.Equal(t, file, filename) + assert.NoError(t, err) +} + func TestDefault(t *testing.T) { SetDefault("age", 45) assert.Equal(t, 45, Get("age"))