Files
bee/audit/internal/app/app_format_test.go
T

71 lines
1.8 KiB
Go

package app
import (
"testing"
"bee/audit/internal/schema"
)
// TestFormatGPULineIgnoresNonGPUSameVendorDevice guards the bug where
// isGPUDevice treated any NVIDIA-vendor PCIe device as a GPU regardless of
// class (a fallback for "NVIDIA devices sometimes expose class values
// outside the standard GPU set"). That fallback misclassified same-vendor
// companion devices — e.g. NVSwitch/NVLink bridges, or an NVIDIA-branded NIC
// — as compute GPUs, inflating the "GPU: N x <model>" audit summary line.
func TestFormatGPULineIgnoresNonGPUSameVendorDevice(t *testing.T) {
vendor := 0x10de // collector.NvidiaVendorID
bridgeClass := "Bridge"
bridgeModel := "NVSwitch"
gpuClass := "VideoController"
gpuModel := "H100"
devices := []schema.HardwarePCIeDevice{
{DeviceClass: &bridgeClass, VendorID: &vendor, Model: &bridgeModel},
{DeviceClass: &gpuClass, VendorID: &vendor, Model: &gpuModel},
}
got := formatGPULine(devices)
want := "GPU: 1 x H100"
if got != want {
t.Fatalf("formatGPULine() = %q, want %q", got, want)
}
}
func TestFormatSATDetail(t *testing.T) {
raw := `run_at_utc=2026-09-12T16:30:00Z
01-cpu_status=OK
storage_status=FAILED
tpm_status=UNSUPPORTED
overall_status=FAILED
job_ok=1
job_failed=1`
got := formatSATDetail(raw)
want := `Run: 2026-09-12T16:30:00Z
PASS cpu
FAIL storage
SKIP tpm
Overall: FAILED (ok=1 failed=1)`
if got != want {
t.Fatalf("formatSATDetail() = %q, want %q", got, want)
}
}
func TestCleanSummaryKey(t *testing.T) {
for _, tt := range []struct {
input string
want string
}{
{input: "01-cpu", want: "cpu"},
{input: "cpu", want: "cpu"},
{input: "cpu-01", want: "cpu-01"},
{input: "-cpu", want: "-cpu"},
} {
if got := cleanSummaryKey(tt.input); got != tt.want {
t.Errorf("cleanSummaryKey(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}