Files
lingniu-vehicle-ingest/vehicle-data-platform/apps/api/internal/config/config_test.go
T
lingniu d6b957dfc8 feat: sync vehicle monitoring and accumulated platform updates
Add monitoring metrics, numeric sorting, report-time display, vehicle number labels, and map layout fixes. Include accumulated mileage, hydrogen, OneOS authentication, open platform, ingestion, deployment, and UI updates.

Exclude temporary files, generated reports, and credentials. Validate frontend 632 tests and production build, API packages, vehicle-map tests, and release installer tests. Gateway suite has one pre-existing date-sensitive identity throttling test failure reproduced on the parent commit.
2026-10-26 18:05:59 +08:00

91 lines
3.2 KiB
Go

package config
import (
"testing"
"time"
)
func TestLoadReadsRequestTimeout(t *testing.T) {
t.Setenv("REQUEST_TIMEOUT_MS", "1200")
cfg := Load()
if cfg.RequestTimeout != 1200*time.Millisecond {
t.Fatalf("RequestTimeout = %s, want 1.2s", cfg.RequestTimeout)
}
}
func TestLoadReadsPlatformRelease(t *testing.T) {
t.Setenv("PLATFORM_RELEASE", "platform-20260704153005")
cfg := Load()
if cfg.PlatformRelease != "platform-20260704153005" {
t.Fatalf("PlatformRelease = %q", cfg.PlatformRelease)
}
}
func TestLoadReadsAMapServerAPIKey(t *testing.T) {
t.Setenv("AMAP_API_KEY", "server-map-key")
cfg := Load()
if cfg.AMapAPIKey != "server-map-key" {
t.Fatalf("AMapAPIKey = %q", cfg.AMapAPIKey)
}
}
func TestLoadSelectsProductionDataModeWhenMySQLIsConfigured(t *testing.T) {
t.Setenv("DATA_MODE", "")
t.Setenv("MYSQL_DSN", "user:password@tcp(db:3306)/platform")
if cfg := Load(); cfg.DataMode != "production" {
t.Fatalf("DataMode = %q, want production", cfg.DataMode)
}
}
func TestLoadKeepsExplicitMockDataMode(t *testing.T) {
t.Setenv("DATA_MODE", "mock")
t.Setenv("MYSQL_DSN", "user:password@tcp(db:3306)/platform")
if cfg := Load(); cfg.DataMode != "mock" {
t.Fatalf("DataMode = %q, want mock", cfg.DataMode)
}
}
func TestLoadReadsAlertNotificationDispatcherSettings(t *testing.T) {
t.Setenv("ALERT_NOTIFICATION_TARGETS_JSON", `[{"id":"night-shift","label":"夜班负责人","channels":["sms"]}]`)
t.Setenv("ALERT_NOTIFICATION_SMS_URL", "https://gateway.example.test/sms")
t.Setenv("ALERT_NOTIFICATION_SMS_SECRET", "signing-secret")
t.Setenv("ALERT_NOTIFICATION_BATCH_SIZE", "48")
t.Setenv("ALERT_NOTIFICATION_POLL_INTERVAL_MS", "750")
t.Setenv("ALERT_NOTIFICATION_LEASE_SEC", "45")
t.Setenv("ALERT_NOTIFICATION_TIMEOUT_MS", "8000")
cfg := Load()
if cfg.AlertNotificationTargetsJSON == "" || cfg.AlertNotificationSMSURL != "https://gateway.example.test/sms" || cfg.AlertNotificationSMSSecret != "signing-secret" {
t.Fatalf("notification target or gateway settings were not loaded: %+v", cfg)
}
if cfg.AlertNotificationBatchSize != 48 || cfg.AlertNotificationPollInterval != 750*time.Millisecond || cfg.AlertNotificationLease != 45*time.Second || cfg.AlertNotificationTimeout != 8*time.Second {
t.Fatalf("notification worker timing settings were not loaded: %+v", cfg)
}
}
func TestLoadReadsHistoryCleanupAutomationSettings(t *testing.T) {
t.Setenv("HISTORY_EXPORT_CLEANUP_AUTOMATION_ENABLED", "true")
t.Setenv("HISTORY_EXPORT_CLEANUP_POLL_SEC", "45")
t.Setenv("HISTORY_EXPORT_CLEANUP_LEASE_SEC", "420")
cfg := Load()
if !cfg.HistoryCleanupAutomation || cfg.HistoryCleanupPollInterval != 45*time.Second || cfg.HistoryCleanupLease != 7*time.Minute {
t.Fatalf("history cleanup automation settings were not loaded: %+v", cfg)
}
}
func TestLoadReadsOneOSLoginTicketServiceToken(t *testing.T) {
t.Setenv("ONEOS_LOGIN_TICKET_EXCHANGE_PATH", "/auth/inner/v1/sso/vehicle-platform/token-exchange")
t.Setenv("ONEOS_LOGIN_TICKET_SERVICE_TOKEN", "local-fixture-service-credential")
cfg := Load()
if cfg.OneOSLoginTicketExchangePath != "/auth/inner/v1/sso/vehicle-platform/token-exchange" || cfg.OneOSLoginTicketServiceToken != "local-fixture-service-credential" {
t.Fatal("OneOS login-ticket service configuration was not loaded")
}
}