mirror of https://github.com/spf13/viper.git
Added test for UnsupportedConfigFile
This commit is contained in:
parent
a17eb5155c
commit
b86edb5103
|
@ -200,6 +200,10 @@ func initDirs(t *testing.T) (string, string, func()) {
|
|||
path.Join(dir, config+".toml"),
|
||||
[]byte("key = \"value is "+dir+"\"\n"),
|
||||
0640)
|
||||
err = ioutil.WriteFile(
|
||||
path.Join(dir, config+".notsupported"),
|
||||
[]byte("key = \"value is"+dir+"\"\n"),
|
||||
0640)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
|
@ -725,6 +729,24 @@ func TestDirsSearch(t *testing.T) {
|
|||
assert.Equal(t, `value is `+path.Base(v.configPaths[0]), v.GetString(`key`))
|
||||
}
|
||||
|
||||
func TestUnsupportedConfigFileType(t *testing.T) {
|
||||
root, config, cleanup := initDirs(t)
|
||||
defer cleanup()
|
||||
|
||||
v := New()
|
||||
v.SetConfigName(config)
|
||||
v.SetConfigType("notsupported")
|
||||
entries, err := ioutil.ReadDir(root)
|
||||
for _, e := range entries {
|
||||
if e.IsDir() {
|
||||
v.AddConfigPath(e.Name())
|
||||
}
|
||||
}
|
||||
err = v.ReadInConfig()
|
||||
|
||||
assert.Equal(t, reflect.TypeOf(UnsupportedConfigError("")), reflect.TypeOf(err))
|
||||
}
|
||||
|
||||
func TestWrongDirsSearchNotFound(t *testing.T) {
|
||||
|
||||
_, config, cleanup := initDirs(t)
|
||||
|
|
Loading…
Reference in New Issue