feat: forward optional FastAPI control token

This commit is contained in:
Noel Sabia committed 2026-11-14 04:47:21 +01:00
1 parent 4b9c2da9f7
commit a88bfad1d4
5 files changed
+70 -23

No files matched your search

+8 -1
View File
@@ -6,7 +6,7 @@ import (
)
func TestLoadDefaults(t *testing.T) {
for _, key := range []string{"PORT", "DATA_DIR", "FASTAPI_URL", "CONTROL_USER", "CONTROL_PASS", "SSE_HEARTBEAT", "ML_TIMEOUT"} {
for _, key := range []string{"PORT", "DATA_DIR", "FASTAPI_URL", "CONTROL_USER", "CONTROL_PASS", "CONTROL_TOKEN", "SSE_HEARTBEAT", "ML_TIMEOUT"} {
t.Setenv(key, "")
}
cfg := Load()
@@ -25,6 +25,9 @@ func TestLoadDefaults(t *testing.T) {
if cfg.ControlAuthConfigured() {
t.Error("control auth should be unconfigured by default")
}
if cfg.ControlToken != "" {
t.Errorf("ControlToken=%q, want empty by default", cfg.ControlToken)
}
}
func TestLoadFromEnv(t *testing.T) {
@@ -33,6 +36,7 @@ func TestLoadFromEnv(t *testing.T) {
t.Setenv("FASTAPI_URL", "http://ml:8000")
t.Setenv("CONTROL_USER", "user")
t.Setenv("CONTROL_PASS", "pass")
t.Setenv("CONTROL_TOKEN", "token-123")
t.Setenv("SSE_HEARTBEAT", "5s")
t.Setenv("ML_TIMEOUT", "2s")
@@ -40,6 +44,9 @@ func TestLoadFromEnv(t *testing.T) {
if cfg.Addr != ":9999" || cfg.DataDir != "/data" || cfg.FastAPIURL != "http://ml:8000" {
t.Fatalf("cfg=%+v", cfg)
}
if cfg.ControlToken != "token-123" {
t.Fatalf("ControlToken=%q, want token-123", cfg.ControlToken)
}
if cfg.Heartbeat != 5*time.Second || cfg.MLTimeout != 2*time.Second {
t.Fatalf("timeouts: heartbeat=%s ml=%s", cfg.Heartbeat, cfg.MLTimeout)
}