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 <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2024-11-14 10:27:45 -08:00
parent 00fff032c7
commit 6afd0122c9
2 changed files with 13 additions and 4 deletions

View file

@ -18,10 +18,22 @@ type AppConfig struct {
var config *AppConfig var config *AppConfig
func init() {
setDefaults()
viper.Unmarshal(&config)
}
func Get() *AppConfig { func Get() *AppConfig {
return config return config
} }
func GetDefaultConfig() *AppConfig {
var config *AppConfig
setDefaults()
viper.Unmarshal(&config)
return config
}
func Init() error { func Init() error {
setDefaults() setDefaults()

View file

@ -25,12 +25,9 @@ log_compression: false
func TestDefaultConfigs(t *testing.T) { func TestDefaultConfigs(t *testing.T) {
k := "testdefaultkey" k := "testdefaultkey"
v := "testdefaultval" v := "testdefaultval"
viper.SetDefault(k, v) viper.SetDefault(k, v)
_, err := Parse() if err := Init(); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }