mirror of https://github.com/spf13/viper.git
Create getDefaultConfigFile() test
This commit is contained in:
parent
c21acdd422
commit
aa2bb3a537
|
@ -12,6 +12,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1032,6 +1033,22 @@ func TestWriteConfigYAML(t *testing.T) {
|
||||||
assert.Equal(t, yamlWriteExpected, read)
|
assert.Equal(t, yamlWriteExpected, read)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetDefaultConfigFile(t *testing.T) {
|
||||||
|
v := New()
|
||||||
|
home, err := filepath.Abs("/homedir")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
v.AddConfigPath(home)
|
||||||
|
v.SetConfigName("c")
|
||||||
|
filename, err := v.getDefaultConfigFile()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ext := "json"
|
||||||
|
assert.Equal(t, filename, filepath.Join("/homedir", "c"+"."+ext))
|
||||||
|
}
|
||||||
|
|
||||||
var yamlMergeExampleTgt = []byte(`
|
var yamlMergeExampleTgt = []byte(`
|
||||||
hello:
|
hello:
|
||||||
pop: 37890
|
pop: 37890
|
||||||
|
|
Loading…
Reference in New Issue