2024-11-06 16:01:38 -08:00
|
|
|
package config
|
2024-11-06 13:32:37 -08:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
`
|
2024-11-06 16:01:38 -08:00
|
|
|
// the config file is stored in the project root
|
|
|
|
|
viper.AddConfigPath("../..")
|
2024-11-06 13:32:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// test that default configs are working
|
|
|
|
|
func TestDefaultConfigs(t *testing.T) {
|
|
|
|
|
k := "testdefaultkey"
|
|
|
|
|
v := "testdefaultval"
|
|
|
|
|
viper.SetDefault(k, v)
|
|
|
|
|
|
2024-11-14 10:27:45 -08:00
|
|
|
if err := Init(); err != nil {
|
2024-11-06 13:32:37 -08:00
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if viper.GetString(k) != v {
|
|
|
|
|
t.Errorf("want %s, got %s", v, viper.GetString(k))
|
|
|
|
|
}
|
|
|
|
|
}
|