HTTP 用 Gin,配置用 Viper,日志用 zap,数据用 sqlx;保留原有接口与会商行为。 顺带补上就绪探活、请求号、滚动日志、systemd 与 Dockerfile。 Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
// 这些用例锁住「环境变量怎么解释」,避免换 Viper 后联调缺省或 demo 开关被悄悄改掉。
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
t.Setenv("ANALYSIS_MODE", "")
|
|
t.Setenv("EBA_WORKER_DEMO_ENABLED", "")
|
|
t.Setenv("SERVER_PORT", "")
|
|
// 空字符串按「没配」处理,应回到 live 且不跑 demo。
|
|
c := Load()
|
|
if c.AnalysisMode != "live" {
|
|
t.Fatalf("mode=%s", c.AnalysisMode)
|
|
}
|
|
if c.DemoEnabled {
|
|
t.Fatal("live 且未显式打开 demo 时不应跑假进度")
|
|
}
|
|
if c.Port != 18097 {
|
|
t.Fatalf("port=%d", c.Port)
|
|
}
|
|
}
|
|
|
|
func TestDemoModeForcesWorker(t *testing.T) {
|
|
t.Setenv("ANALYSIS_MODE", "demo")
|
|
t.Setenv("EBA_WORKER_DEMO_ENABLED", "false")
|
|
c := Load()
|
|
if !c.DemoEnabled {
|
|
t.Fatal("ANALYSIS_MODE=demo 必须开假进度,忽略 worker 开关")
|
|
}
|
|
}
|
|
|
|
func TestLiveExplicitDemo(t *testing.T) {
|
|
t.Setenv("ANALYSIS_MODE", "live")
|
|
t.Setenv("EBA_WORKER_DEMO_ENABLED", "yes")
|
|
c := Load()
|
|
if !c.DemoEnabled {
|
|
t.Fatal("live 下显式 EBA_WORKER_DEMO_ENABLED=yes 应保留假进度")
|
|
}
|
|
}
|
|
|
|
func TestStrictRejectsWeakPassword(t *testing.T) {
|
|
c := Config{
|
|
AnalysisMode: "live",
|
|
Port: 18097,
|
|
DBDSN: "x",
|
|
DeerFlowPassword: "123ewq",
|
|
DeerFlowBaseURL: "http://127.0.0.1:8001",
|
|
StrictConfig: true,
|
|
DemoEnabled: true,
|
|
}
|
|
_, err := c.Validate()
|
|
if err == nil {
|
|
t.Fatal("live + strict 即使同时开了 demo,也不能放过默认口令")
|
|
}
|
|
}
|