From 6afd0122c918f8409e8aed0e3b9f3ed8157e35e3 Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Thu, 14 Nov 2024 10:27:45 -0800 Subject: [PATCH] Fix config unit tests Recent changes to config and logging modules have left the tests needing to initialize both config and logging packages. This commit updates the config module to automatically initialize into at least useful defaults at module load time. This commit also fixes the config unit tests by using the more up to date interface that the package provides. Signed-off-by: Ava Affine --- internal/config/config.go | 12 ++++++++++++ internal/config/config_test.go | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 90fc69e..e8f7b5c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -18,10 +18,22 @@ type AppConfig struct { var config *AppConfig +func init() { + setDefaults() + viper.Unmarshal(&config) +} + func Get() *AppConfig { return config } +func GetDefaultConfig() *AppConfig { + var config *AppConfig + setDefaults() + viper.Unmarshal(&config) + return config +} + func Init() error { setDefaults() diff --git a/internal/config/config_test.go b/internal/config/config_test.go index eb9f022..9fef00f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -25,12 +25,9 @@ log_compression: false func TestDefaultConfigs(t *testing.T) { k := "testdefaultkey" v := "testdefaultval" - viper.SetDefault(k, v) - _, err := Parse() - - if err != nil { + if err := Init(); err != nil { t.Error(err) }