Update config from env

This commit is contained in:
Torjus Håkestad 2021-09-14 23:18:58 +02:00
parent 3c79a1de8c
commit 00f16046e0
2 changed files with 7 additions and 0 deletions

View File

@ -43,6 +43,7 @@ func FromReader(r io.Reader) (*Config, error) {
if err := decoder.Decode(&c); err != nil {
return nil, fmt.Errorf("error parsing config file: %w", err)
}
c.UpdateFromEnv()
return &c, c.Verify()
}

View File

@ -98,6 +98,12 @@ func TestConfig(t *testing.T) {
if c.LogLevel != envValues["DOGTAMER_LOGLEVEL"] {
t.Errorf("LogLevel has wrong value: %s", c.LogLevel)
}
t.Cleanup(func() {
for value := range envValues {
os.Unsetenv(value)
}
})
})
t.Run("TestFromEnvInvalid", func(t *testing.T) {
os.Clearenv()