package trafficmgr import ( "testing" "time" "vpn-platform/backend/internal/alertnotify" "vpn-platform/backend/internal/model" "vpn-platform/backend/internal/store" ) func TestConfigurableRateThreshold(t *testing.T) { if err := store.Init(t.TempDir()); err != nil { t.Fatal(err) } if _, err := alertnotify.Save(alertnotify.Input{RateThresholdMbps: 80}); err != nil { t.Fatal(err) } if CheckRateAbnormal(1, 100*1024*1024, 0, 15*time.Second) { t.Fatal("below 80 Mbps should not alert") } if !CheckRateAbnormal(1, 200*1024*1024, 0, 15*time.Second) { t.Fatal("above 80 Mbps should alert") } var count int64 store.DB.Model(&model.ConnectionLog{}).Where("event = ?", "rate_alert").Count(&count) if count != 1 { t.Fatalf("want one alert, got %d", count) } }