Add infrastructure reliability monitoring
This commit is contained in:
38
reliability_test.go
Normal file
38
reliability_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDiskCounterChanges(t *testing.T) {
|
||||
old := DiskMetrics{Reallocated: 1, Pending: 2, CRCErrors: 4}
|
||||
current := DiskMetrics{Reallocated: 2, Pending: 2, CRCErrors: 7}
|
||||
changes := strings.Join(diskCounterChanges(old, current), " ")
|
||||
if !strings.Contains(changes, "Reallocated") || !strings.Contains(changes, "CRC") || strings.Contains(changes, "Pending") {
|
||||
t.Fatalf("unexpected counter changes: %s", changes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseScrub(t *testing.T) {
|
||||
status, at, duration, old := parseScrub("scrub repaired 0B in 01:12:03 with 0 errors on Fri Jan 2 03:04:05 2026")
|
||||
if status != "Завершён" || at == "" || duration != "01:12:03" || !old {
|
||||
t.Fatalf("unexpected scrub: %q %q %q %v", status, at, duration, old)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShutdownDryRunUsesConfiguredOrder(t *testing.T) {
|
||||
settings := UPSShutdownSettings{ChargePercent: 15, RuntimeSeconds: 600, GraceSeconds: 120, GuestOrder: []int{105}}
|
||||
guests := GuestsMetrics{Guests: []GuestMetrics{{VMID: 101, Name: "one", Type: "qemu", Status: "running"}, {VMID: 105, Name: "five", Type: "lxc", Status: "running"}}}
|
||||
steps := buildShutdownDryRun(settings, guests)
|
||||
if len(steps) != 4 || !strings.Contains(steps[1].Target, "105") || !strings.Contains(steps[2].Target, "101") || steps[3].Target != "Proxmox host" {
|
||||
t.Fatalf("unexpected plan: %+v", steps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelfTestOlderThanWeek(t *testing.T) {
|
||||
if !selfTestOlderThanWeek(time.Now().Add(-8*24*time.Hour).Format(time.RFC3339)) || selfTestOlderThanWeek(time.Now().Format(time.RFC3339)) {
|
||||
t.Fatal("self-test age evaluation is incorrect")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user