fix: option to skip flags, to avoid breaking the tests

This commit is contained in:
Deluan 2020-01-26 18:00:10 -05:00
parent 0ff741b394
commit cc6eacd608
2 changed files with 10 additions and 7 deletions

View file

@ -34,8 +34,8 @@ type nd struct {
var Server = &nd{} var Server = &nd{}
func NewWithPath(path string) *multiconfig.DefaultLoader { func newWithPath(path string, skipFlags ...bool) *multiconfig.DefaultLoader {
loaders := []multiconfig.Loader{} var loaders []multiconfig.Loader
// Read default values defined via tag fields "default" // Read default values defined via tag fields "default"
loaders = append(loaders, &multiconfig.TagLoader{}) loaders = append(loaders, &multiconfig.TagLoader{})
@ -55,9 +55,12 @@ func NewWithPath(path string) *multiconfig.DefaultLoader {
} }
e := &multiconfig.EnvironmentLoader{} e := &multiconfig.EnvironmentLoader{}
f := &multiconfig.FlagLoader{} loaders = append(loaders, e)
if len(skipFlags) == 0 || !skipFlags[0] {
f := &multiconfig.FlagLoader{}
loaders = append(loaders, f)
}
loaders = append(loaders, e, f)
loader := multiconfig.MultiLoader(loaders...) loader := multiconfig.MultiLoader(loaders...)
d := &multiconfig.DefaultLoader{} d := &multiconfig.DefaultLoader{}
@ -66,8 +69,8 @@ func NewWithPath(path string) *multiconfig.DefaultLoader {
return d return d
} }
func LoadFromFile(confFile string) { func LoadFromFile(confFile string, skipFlags ...bool) {
m := NewWithPath(confFile) m := newWithPath(confFile, skipFlags...)
err := m.Load(Server) err := m.Load(Server)
if err == flag.ErrHelp { if err == flag.ErrHelp {
os.Exit(1) os.Exit(1)

View file

@ -23,7 +23,7 @@ func Init(t *testing.T, skipOnShort bool) {
confPath, _ := filepath.Abs(filepath.Join(appPath, "tests", "navidrome-test.toml")) confPath, _ := filepath.Abs(filepath.Join(appPath, "tests", "navidrome-test.toml"))
os.Chdir(appPath) os.Chdir(appPath)
conf.LoadFromFile(confPath) conf.LoadFromFile(confPath, true)
noLog := os.Getenv("NOLOG") noLog := os.Getenv("NOLOG")
if noLog != "" { if noLog != "" {