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>
37 lines
620 B
Go
37 lines
620 B
Go
package config
|
|
|
|
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
|
|
`
|
|
// the config file is stored in the project root
|
|
viper.AddConfigPath("../..")
|
|
}
|
|
|
|
// test that default configs are working
|
|
func TestDefaultConfigs(t *testing.T) {
|
|
k := "testdefaultkey"
|
|
v := "testdefaultval"
|
|
viper.SetDefault(k, v)
|
|
|
|
if err := Init(); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if viper.GetString(k) != v {
|
|
t.Errorf("want %s, got %s", v, viper.GetString(k))
|
|
}
|
|
}
|