spf13/viper#73 More specific test to document current behavior

This commit is contained in:
Vlad Didenko 2015-05-27 16:03:21 -05:00
parent fb16a6b8d5
commit 033e966e68

View file

@ -11,6 +11,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"reflect"
"sort" "sort"
"strings" "strings"
"testing" "testing"
@ -632,7 +633,7 @@ 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 TestWrongDirsSearchNotFoundOK(t *testing.T) { func TestWrongDirsSearchNotFoundHasCWDConfig(t *testing.T) {
_, config, cleanup := initDirs(t) _, config, cleanup := initDirs(t)
defer cleanup() defer cleanup()
@ -650,3 +651,25 @@ func TestWrongDirsSearchNotFoundOK(t *testing.T) {
// Should not see the value "root" which comes from config in CWD // Should not see the value "root" which comes from config in CWD
assert.Equal(t, `default`, v.GetString(`key`)) assert.Equal(t, `default`, v.GetString(`key`))
} }
func TestWrongDirsSearchNotFoundNoCWDConfig(t *testing.T) {
_, config, cleanup := initDirs(t)
defer cleanup()
os.Remove(config + ".toml")
v := New()
v.SetConfigName(config)
v.SetDefault(`key`, `default`)
v.AddConfigPath(`whattayoutalkingbout`)
v.AddConfigPath(`thispathaintthere`)
err := v.ReadInConfig()
assert.Equal(t, reflect.TypeOf(UnsupportedConfigError("")), reflect.TypeOf(err))
// Even though config did not load and the error might have
// been ignored by the client, the default still loads
assert.Equal(t, `default`, v.GetString(`key`))
}