internal: add additional error handling in config loader
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
10b48b27b0
commit
55739ee982
|
@ -49,7 +49,10 @@ func (c *Config) Setup(paths ...string) {
|
|||
log.WithError(err).Info("failed to load config, skipping")
|
||||
}
|
||||
}
|
||||
c.fromEnv()
|
||||
err := c.fromEnv()
|
||||
if err != nil {
|
||||
log.WithError(err).Info("failed to load env vars")
|
||||
}
|
||||
c.configureLogger()
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ import (
|
|||
func TestConfigEnv(t *testing.T) {
|
||||
os.Setenv("AUTHENTIK_SECRET_KEY", "bar")
|
||||
cfg = nil
|
||||
Get().fromEnv()
|
||||
if err := Get().fromEnv(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
assert.Equal(t, "bar", Get().SecretKey)
|
||||
}
|
||||
|
||||
|
@ -20,7 +22,9 @@ func TestConfigEnv_Scheme(t *testing.T) {
|
|||
os.Setenv("foo", "bar")
|
||||
os.Setenv("AUTHENTIK_SECRET_KEY", "env://foo")
|
||||
cfg = nil
|
||||
Get().fromEnv()
|
||||
if err := Get().fromEnv(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
assert.Equal(t, "bar", Get().SecretKey)
|
||||
}
|
||||
|
||||
|
@ -30,10 +34,15 @@ func TestConfigEnv_File(t *testing.T) {
|
|||
log.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
file.Write([]byte("bar"))
|
||||
_, err = file.Write([]byte("bar"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
os.Setenv("AUTHENTIK_SECRET_KEY", fmt.Sprintf("file://%s", file.Name()))
|
||||
cfg = nil
|
||||
Get().fromEnv()
|
||||
if err := Get().fromEnv(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
assert.Equal(t, "bar", Get().SecretKey)
|
||||
}
|
||||
|
|
Reference in a new issue