Added test for UnsupportedConfigFile

This commit is contained in:
Matt Rickard 2016-08-08 12:20:52 -07:00
parent a17eb5155c
commit b86edb5103
1 changed files with 22 additions and 0 deletions

View File

@ -200,6 +200,10 @@ func initDirs(t *testing.T) (string, string, func()) {
path.Join(dir, config+".toml"), path.Join(dir, config+".toml"),
[]byte("key = \"value is "+dir+"\"\n"), []byte("key = \"value is "+dir+"\"\n"),
0640) 0640)
err = ioutil.WriteFile(
path.Join(dir, config+".notsupported"),
[]byte("key = \"value is"+dir+"\"\n"),
0640)
assert.Nil(t, err) 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`)) 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) { func TestWrongDirsSearchNotFound(t *testing.T) {
_, config, cleanup := initDirs(t) _, config, cleanup := initDirs(t)