Add config parsing

This commit is contained in:
Piper Pentagram 2024-11-06 13:32:37 -08:00
parent 44a2e7d6c8
commit bea76cd380
6 changed files with 198 additions and 5 deletions

38
config_test.go Normal file
View file

@ -0,0 +1,38 @@
package main
import (
"testing"
"github.com/spf13/viper"
)
var testConfig string
func init() {
testConfig = `
log_file: "bingobot.log"
log_dir: "log"
log_max_size_mb: 500
log_max_backups: 3
log_max_age_days: 365
log_compression: false
`
}
// test that default configs are working
func TestDefaultConfigs(t *testing.T) {
k := "testdefaultkey"
v := "testdefaultval"
viper.SetDefault(k, v)
err := parseConfigs()
if err != nil {
t.Error(err)
}
if viper.GetString(k) != v {
t.Errorf("want %s, got %s", v, viper.GetString(k))
}
}