refuse to start if the config file is invalid
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
c71f0426ae
commit
d8b040e57c
2 changed files with 4 additions and 4 deletions
|
@ -734,9 +734,9 @@ func LoadConfig(configDir, configFile string) error {
|
|||
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
|
||||
logger.Debug(logSender, "", "no configuration file found")
|
||||
} else {
|
||||
// should we return the error and not start here?
|
||||
logger.Warn(logSender, "", "error loading configuration file: %v", err)
|
||||
logger.WarnToConsole("error loading configuration file: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
checkOverrideDefaultSettings()
|
||||
|
|
|
@ -68,11 +68,11 @@ func TestLoadConfigTest(t *testing.T) {
|
|||
confName := tempConfigName + ".json" //nolint:goconst
|
||||
configFilePath := filepath.Join(configDir, confName)
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
assert.Error(t, err)
|
||||
err = os.WriteFile(configFilePath, []byte("{invalid json}"), os.ModePerm)
|
||||
assert.NoError(t, err)
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
assert.Error(t, err)
|
||||
err = os.WriteFile(configFilePath, []byte(`{"sftpd": {"max_auth_tries": "a"}}`), os.ModePerm)
|
||||
assert.NoError(t, err)
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
|
@ -1587,7 +1587,7 @@ func TestConfigFromEnv(t *testing.T) {
|
|||
os.Unsetenv("SFTPGO_HTTPD__SETUP__INSTALLATION_CODE")
|
||||
os.Unsetenv("SFTPGO_ACME__HTTP01_CHALLENGE_PORT")
|
||||
})
|
||||
err := config.LoadConfig(".", "invalid config")
|
||||
err := config.LoadConfig(configDir, "")
|
||||
assert.NoError(t, err)
|
||||
sftpdConfig := config.GetSFTPDConfig()
|
||||
assert.Equal(t, "127.0.0.1", sftpdConfig.Bindings[0].Address)
|
||||
|
|
Loading…
Reference in a new issue