Post-repair hardware validation pipeline for Proxmox cluster hosts. Go orchestrator + in-image agent + mkosi live image + bundled dnsmasq PXE + SQLite + HTMX/SSE UI + notify registry + janitor + full docs.
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
package spec
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"vetting/internal/model"
|
||||
)
|
||||
|
||||
func TestDiffEmptySpec(t *testing.T) {
|
||||
if d := Diff(&Spec{}, &Inventory{}); len(d) != 0 {
|
||||
t.Fatalf("empty spec → empty diff, got %v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffCPUMismatch(t *testing.T) {
|
||||
exp := &Spec{CPU: &CPUSpec{Model: "E5-2680 v4", LogicalCores: 28}}
|
||||
act := &Inventory{CPU: CPUSpec{Model: "Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz", LogicalCores: 16}}
|
||||
d := Diff(exp, act)
|
||||
if len(d) != 1 || d[0].Field != "cpu.logical_cores" || d[0].Severity != "critical" {
|
||||
t.Fatalf("expected logical_cores critical, got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffCPUModelSubstringMatch(t *testing.T) {
|
||||
exp := &Spec{CPU: &CPUSpec{Model: "E5-2680 v4"}}
|
||||
act := &Inventory{CPU: CPUSpec{Model: "Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz"}}
|
||||
if d := Diff(exp, act); len(d) != 0 {
|
||||
t.Fatalf("substring should match, got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffMemoryTolerance(t *testing.T) {
|
||||
exp := &Spec{Memory: &MemorySpec{TotalGiB: 128}}
|
||||
act := &Inventory{Memory: MemorySpec{TotalGiB: 127}}
|
||||
if d := Diff(exp, act); len(d) != 0 {
|
||||
t.Fatalf("1 GiB variance should be tolerated, got %+v", d)
|
||||
}
|
||||
act2 := &Inventory{Memory: MemorySpec{TotalGiB: 112}} // missing stick
|
||||
d := Diff(exp, act2)
|
||||
if len(d) != 1 || d[0].Field != "memory.total_gib" {
|
||||
t.Fatalf("16 GiB drop should be critical, got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffDisksMissingAndUnexpected(t *testing.T) {
|
||||
exp := &Spec{Disks: []DiskSpec{{Serial: "A", SizeGB: 1000}, {Serial: "B", SizeGB: 500}}}
|
||||
act := &Inventory{Disks: []DiskSpec{{Serial: "A", SizeGB: 1000}, {Serial: "C", SizeGB: 32}}}
|
||||
d := Diff(exp, act)
|
||||
// Expect: disk B missing, disk C unexpected.
|
||||
got := map[string]bool{}
|
||||
for _, row := range d {
|
||||
got[row.Field] = true
|
||||
}
|
||||
if !got["disks[B].present"] {
|
||||
t.Fatalf("expected disks[B].present critical; got %+v", d)
|
||||
}
|
||||
if !got["disks[unexpected C]"] {
|
||||
t.Fatalf("expected disks[unexpected C] critical; got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffDisksSerialCaseInsensitive(t *testing.T) {
|
||||
exp := &Spec{Disks: []DiskSpec{{Serial: "wd-abc123", SizeGB: 1000}}}
|
||||
act := &Inventory{Disks: []DiskSpec{{Serial: "WD-ABC123", SizeGB: 1000}}}
|
||||
if d := Diff(exp, act); len(d) != 0 {
|
||||
t.Fatalf("serial compare must be case-insensitive, got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffNICMAC(t *testing.T) {
|
||||
exp := &Spec{NICs: []NICSpec{{MAC: "aa:bb:cc:dd:ee:ff", SpeedGbps: 10}}}
|
||||
act := &Inventory{NICs: []NICSpec{{MAC: "aa:bb:cc:dd:ee:ff", SpeedGbps: 1}}}
|
||||
d := Diff(exp, act)
|
||||
if len(d) != 1 || d[0].Field != "nics[aa:bb:cc:dd:ee:ff].speed_gbps" {
|
||||
t.Fatalf("expected speed mismatch, got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffGPUCount(t *testing.T) {
|
||||
exp := &Spec{GPUs: []GPUSpec{{Model: "NVIDIA RTX 3090"}, {Model: "NVIDIA RTX 3090"}}}
|
||||
act := &Inventory{GPUs: []GPUSpec{{Model: "nvidia rtx 3090"}}}
|
||||
d := Diff(exp, act)
|
||||
if len(d) != 1 || d[0].Field != "gpus[nvidia rtx 3090].count" {
|
||||
t.Fatalf("expected GPU count critical, got %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseValidYAML(t *testing.T) {
|
||||
src := `
|
||||
cpu:
|
||||
model: "E5-2680 v4"
|
||||
logical_cores: 28
|
||||
memory:
|
||||
total_gib: 128
|
||||
disks:
|
||||
- serial: A
|
||||
size_gb: 1000
|
||||
`
|
||||
s, err := Parse(src)
|
||||
if err != nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
if s.CPU == nil || s.CPU.LogicalCores != 28 {
|
||||
t.Fatalf("cpu not parsed: %+v", s)
|
||||
}
|
||||
if len(s.Disks) != 1 || s.Disks[0].Serial != "A" {
|
||||
t.Fatalf("disks not parsed: %+v", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffSeverityAlwaysCritical(t *testing.T) {
|
||||
exp := &Spec{CPU: &CPUSpec{LogicalCores: 8}}
|
||||
act := &Inventory{CPU: CPUSpec{LogicalCores: 4}}
|
||||
d := Diff(exp, act)
|
||||
var got []model.SpecDiff = d
|
||||
for _, row := range got {
|
||||
if row.Severity != "critical" {
|
||||
t.Fatalf("phase-3 rule: every diff is critical; got %q for %s", row.Severity, row.Field)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user