mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-19 10:33:29 +00:00
test(alerts): prove stopped guests preserve posture incidents
This commit is contained in:
parent
c33ed56f1f
commit
37e3c81b03
1 changed files with 29 additions and 0 deletions
|
|
@ -15074,6 +15074,12 @@ func TestCheckGuest(t *testing.T) {
|
|||
|
||||
backupStateID := buildCanonicalStateID("vm100", "vm100-backup-age")
|
||||
snapshotStateID := buildCanonicalStateID("vm100", "vm100/snapshot:snap1")
|
||||
cpuStateID := canonicalMetricStateID("vm100", "cpu")
|
||||
resolvedIDs := make(chan string, 3)
|
||||
m.SetResolvedCallback(func(alertID string) {
|
||||
resolvedIDs <- alertID
|
||||
})
|
||||
|
||||
m.mu.Lock()
|
||||
m.activeAlerts[backupStateID] = &Alert{
|
||||
ID: backupStateID,
|
||||
|
|
@ -15091,6 +15097,11 @@ func TestCheckGuest(t *testing.T) {
|
|||
CanonicalSpecID: "vm100/snapshot:snap1",
|
||||
CanonicalState: snapshotStateID,
|
||||
}
|
||||
m.activeAlerts[cpuStateID] = &Alert{
|
||||
ID: cpuStateID,
|
||||
ResourceID: "vm100",
|
||||
Type: "cpu",
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
vm := models.VM{
|
||||
|
|
@ -15102,9 +15113,24 @@ func TestCheckGuest(t *testing.T) {
|
|||
|
||||
m.CheckGuest(vm, "pve1")
|
||||
|
||||
select {
|
||||
case resolvedID := <-resolvedIDs:
|
||||
if resolvedID != cpuStateID {
|
||||
t.Fatalf("expected only the CPU metric alert to resolve, got %q", resolvedID)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("expected the CPU metric alert to emit a resolution callback")
|
||||
}
|
||||
select {
|
||||
case resolvedID := <-resolvedIDs:
|
||||
t.Fatalf("unexpected posture-alert resolution callback %q", resolvedID)
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
|
||||
m.mu.RLock()
|
||||
_, backupExists := testLookupActiveAlert(t, m, backupStateID)
|
||||
_, snapshotExists := testLookupActiveAlert(t, m, snapshotStateID)
|
||||
_, cpuExists := testLookupActiveAlert(t, m, cpuStateID)
|
||||
m.mu.RUnlock()
|
||||
|
||||
if !backupExists {
|
||||
|
|
@ -15113,6 +15139,9 @@ func TestCheckGuest(t *testing.T) {
|
|||
if !snapshotExists {
|
||||
t.Error("expected snapshot-age alert to remain active for a non-running guest")
|
||||
}
|
||||
if cpuExists {
|
||||
t.Error("expected CPU metric alert to resolve for a non-running guest")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("running guest clears powered-off alert", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue