From b86edb5103117747dc5bc6d006ca68d0250c848b Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Mon, 8 Aug 2016 12:20:52 -0700 Subject: [PATCH] Added test for UnsupportedConfigFile --- viper_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/viper_test.go b/viper_test.go index 7372ef7..1742cb0 100644 --- a/viper_test.go +++ b/viper_test.go @@ -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)