mirror of
https://github.com/spf13/viper
synced 2025-05-15 00:27:18 +00:00
Merge cb23e03ea4
into 0d7e8034ee
This commit is contained in:
commit
29d78e2099
2 changed files with 30 additions and 4 deletions
14
viper.go
14
viper.go
|
@ -2108,10 +2108,16 @@ func (v *Viper) getConfigFile() (string, error) {
|
||||||
func (v *Viper) searchInPath(in string) (filename string) {
|
func (v *Viper) searchInPath(in string) (filename string) {
|
||||||
jww.DEBUG.Println("Searching for config in ", in)
|
jww.DEBUG.Println("Searching for config in ", in)
|
||||||
for _, ext := range SupportedExts {
|
for _, ext := range SupportedExts {
|
||||||
jww.DEBUG.Println("Checking for", filepath.Join(in, v.configName+"."+ext))
|
var configFilePlusExt string
|
||||||
if b, _ := exists(v.fs, filepath.Join(in, v.configName+"."+ext)); b {
|
if ext != "" {
|
||||||
jww.DEBUG.Println("Found: ", filepath.Join(in, v.configName+"."+ext))
|
configFilePlusExt = v.configName + "." + ext
|
||||||
return filepath.Join(in, v.configName+"."+ext)
|
} else {
|
||||||
|
configFilePlusExt = v.configName
|
||||||
|
}
|
||||||
|
jww.DEBUG.Println("Checking for", filepath.Join(in, configFilePlusExt))
|
||||||
|
if b, _ := exists(v.fs, filepath.Join(in, configFilePlusExt)); b {
|
||||||
|
jww.DEBUG.Println("Found: ", filepath.Join(in, configFilePlusExt))
|
||||||
|
return filepath.Join(in, configFilePlusExt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1375,6 +1375,26 @@ func TestSub(t *testing.T) {
|
||||||
assert.Equal(t, (*Viper)(nil), subv)
|
assert.Equal(t, (*Viper)(nil), subv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyExtension(t *testing.T) {
|
||||||
|
v := New()
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
v.SetFs(fs)
|
||||||
|
v.SetConfigName("config")
|
||||||
|
v.SetConfigType("json")
|
||||||
|
v.AddConfigPath("/etc/app/")
|
||||||
|
SupportedExts = append(SupportedExts, "")
|
||||||
|
|
||||||
|
err := afero.WriteFile(fs, "/etc/app/config", jsonExample, 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = v.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var hclWriteExpected = []byte(`"foos" = {
|
var hclWriteExpected = []byte(`"foos" = {
|
||||||
"foo" = {
|
"foo" = {
|
||||||
"key" = 1
|
"key" = 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue