mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
spf13/viper#73 More specific test to document current behavior
This commit is contained in:
parent
fb16a6b8d5
commit
033e966e68
1 changed files with 24 additions and 1 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -632,7 +633,7 @@ func TestDirsSearch(t *testing.T) {
|
|||
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)
|
||||
defer cleanup()
|
||||
|
@ -650,3 +651,25 @@ func TestWrongDirsSearchNotFoundOK(t *testing.T) {
|
|||
// Should not see the value "root" which comes from config in CWD
|
||||
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`))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue