42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateRejectsDeprecatedTinodeDatabase(t *testing.T) {
|
|
cfg := defaultConfig()
|
|
cfg.MySQL.DSN = "root:root@tcp(127.0.0.1:3306)/tinode?parseTime=true"
|
|
|
|
err := cfg.validate()
|
|
if err == nil || !strings.Contains(err.Error(), "tinode is deprecated") {
|
|
t.Fatalf("validate() error = %v, want deprecated database error", err)
|
|
}
|
|
}
|
|
|
|
func TestDefaultConfigUsesMeetingIMDatabase(t *testing.T) {
|
|
cfg := defaultConfig()
|
|
if err := cfg.validate(); err != nil {
|
|
t.Fatalf("default config validation failed: %v", err)
|
|
}
|
|
if !strings.Contains(cfg.MySQL.DSN, "/meeting_im?") {
|
|
t.Fatalf("default mysql dsn = %q, want meeting_im database", cfg.MySQL.DSN)
|
|
}
|
|
if cfg.MySQL.MaxOpenConns != 15 || cfg.MySQL.MaxIdleConns != 5 {
|
|
t.Fatalf("default mysql pool = %d/%d, want 15/5", cfg.MySQL.MaxOpenConns, cfg.MySQL.MaxIdleConns)
|
|
}
|
|
}
|
|
|
|
func TestApplyEnvOverridesMySQLPool(t *testing.T) {
|
|
t.Setenv("IM_WORKBENCH_MYSQL_MAX_OPEN_CONNS", "12")
|
|
t.Setenv("IM_WORKBENCH_MYSQL_MAX_IDLE_CONNS", "4")
|
|
cfg := defaultConfig()
|
|
|
|
applyEnv(cfg)
|
|
|
|
if cfg.MySQL.MaxOpenConns != 12 || cfg.MySQL.MaxIdleConns != 4 {
|
|
t.Fatalf("mysql pool = %d/%d, want 12/4", cfg.MySQL.MaxOpenConns, cfg.MySQL.MaxIdleConns)
|
|
}
|
|
}
|