Use hostname-first agent names so the same forged binary on many machines stays distinct at scale. Add WebSocket RTT latency on the roster and Crucible, fleet delete and uninstall flows, live alert config reload, and non-blocking pool setup. Fix Crucible phantom agents after delete, posture scan targeting, and USB portability (config data_dir, LAUNCH sync).
42 lines
949 B
Go
42 lines
949 B
Go
package alerts
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"crypto-miner-server/internal/models"
|
|
)
|
|
|
|
func TestFormatPct(t *testing.T) {
|
|
if formatPct(50.55) != "50.5" {
|
|
t.Fatalf("expected 50.5 got %s", formatPct(50.55))
|
|
}
|
|
}
|
|
|
|
func TestEvaluatorOfflineAlert(t *testing.T) {
|
|
var fired []AlertEvent
|
|
e := &Evaluator{
|
|
thresholds: func() Thresholds { return Thresholds{OfflineMinutes: 5} },
|
|
notify: func() NotifyConfig { return NotifyConfig{} },
|
|
broadcast: func(ev AlertEvent) { fired = append(fired, ev) },
|
|
baseline: make(map[string]float64),
|
|
lastFired: make(map[string]time.Time),
|
|
cooldown: 0,
|
|
}
|
|
|
|
agent := &models.Agent{
|
|
ID: "a1",
|
|
Name: "worker-1",
|
|
Status: "offline",
|
|
LastSeen: time.Now().Add(-10 * time.Minute),
|
|
}
|
|
|
|
e.checkOffline(agent, e.thresholds(), time.Now())
|
|
if len(fired) != 1 {
|
|
t.Fatalf("expected 1 alert, got %d", len(fired))
|
|
}
|
|
if fired[0].Type != "offline" {
|
|
t.Fatalf("expected offline alert")
|
|
}
|
|
}
|