Files
bee/audit/internal/collector/nic_mellanox_test.go
Michael Chus 7d2e904d14 Bring codebase into compliance with bible contracts (A–E)
A (hardware-ingest-json v2.8-2.9): remove sensor location fields from schema
and collector; tag HardwareMemory.Location as json:"-"; add PlatformConfig to
HardwareSnapshot.

B (no-hardcoded-vendors): consolidate PCI vendor IDs into collector/pci_vendors.go;
replace all vendor-name string checks in isGPUDevice, isNVIDIADevice, isMellanoxDevice,
isAMDGPUDevice, matchesGPUVendor (sat_overlay), and validateIsVendorGPU (page_validate)
with numeric vendor_id comparisons.

C (module-structure): split app/app.go (1413 lines) into app.go + app_format.go,
app_network.go, app_services.go, app_packs.go, app_install.go — no logic changes.

D (go-code-style): wrap bare return err in interfaceAdminState and
interfaceIPv4Addrs (platform/network.go) with fmt.Errorf context including
the interface name.

E (go-project-bible): add bible-local/architecture/data-model.md and
bible-local/architecture/api-surface.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-13 14:32:08 +03:00

119 lines
2.9 KiB
Go

package collector
import (
"bee/audit/internal/schema"
"fmt"
"testing"
)
func TestParseMstflintQuery(t *testing.T) {
raw := `Device #1:
----------
FW Version: 28.39.1002
Board Serial Number: MT1234ABC
`
fw, serial := parseMstflintQuery(raw)
if fw != "28.39.1002" {
t.Fatalf("firmware: got %q", fw)
}
if serial != "MT1234ABC" {
t.Fatalf("serial: got %q", serial)
}
}
func TestParseEthtoolFirmwareInfo(t *testing.T) {
raw := `driver: mlx5_core
version: 6.6.31-0-lts
firmware-version: 28.39.1002 (MT_0000000000)
bus-info: 0000:18:00.0
`
fw := parseEthtoolFirmwareInfo(raw)
if fw != "28.39.1002 (MT_0000000000)" {
t.Fatalf("firmware: got %q", fw)
}
}
func TestEnrichPCIeWithMellanox_mstflint(t *testing.T) {
origMst := mstflintQuery
origEth := ethtoolInfoQuery
origIfaces := netIfacesByBDF
t.Cleanup(func() {
mstflintQuery = origMst
ethtoolInfoQuery = origEth
netIfacesByBDF = origIfaces
})
mstflintQuery = func(bdf string) (string, error) {
if bdf != "0000:18:00.0" {
t.Fatalf("unexpected bdf: %s", bdf)
}
return "FW Version: 28.39.1002\nBoard Serial Number: SN-MST-001\n", nil
}
ethtoolInfoQuery = func(string) (string, error) {
t.Fatal("ethtool should not be called when mstflint succeeds")
return "", nil
}
netIfacesByBDF = func(string) []string { return nil }
vendorID := MellanoxVendorID
bdf := "0000:18:00.0"
manufacturer := "Mellanox Technologies"
devs := []schema.HardwarePCIeDevice{{
VendorID: &vendorID,
BDF: &bdf,
Manufacturer: &manufacturer,
}}
out := enrichPCIeWithMellanox(devs)
if out[0].Firmware == nil || *out[0].Firmware != "28.39.1002" {
t.Fatalf("firmware: got %v", out[0].Firmware)
}
if out[0].SerialNumber == nil || *out[0].SerialNumber != "SN-MST-001" {
t.Fatalf("serial: got %v", out[0].SerialNumber)
}
}
func TestEnrichPCIeWithMellanox_fallbackEthtool(t *testing.T) {
origMst := mstflintQuery
origEth := ethtoolInfoQuery
origIfaces := netIfacesByBDF
t.Cleanup(func() {
mstflintQuery = origMst
ethtoolInfoQuery = origEth
netIfacesByBDF = origIfaces
})
mstflintQuery = func(string) (string, error) {
return "", fmt.Errorf("mstflint not found")
}
netIfacesByBDF = func(bdf string) []string {
if bdf != "0000:18:00.0" {
t.Fatalf("unexpected bdf: %s", bdf)
}
return []string{"eth0"}
}
ethtoolInfoQuery = func(iface string) (string, error) {
if iface != "eth0" {
t.Fatalf("unexpected iface: %s", iface)
}
return "driver: mlx5_core\nfirmware-version: 28.40.1000\n", nil
}
vendorID := MellanoxVendorID
bdf := "0000:18:00.0"
manufacturer := "NVIDIA Networking"
devs := []schema.HardwarePCIeDevice{{
VendorID: &vendorID,
BDF: &bdf,
Manufacturer: &manufacturer,
}}
out := enrichPCIeWithMellanox(devs)
if out[0].Firmware == nil || *out[0].Firmware != "28.40.1000" {
t.Fatalf("firmware: got %v", out[0].Firmware)
}
if out[0].SerialNumber != nil {
t.Fatalf("serial should stay nil without mstflint, got %v", out[0].SerialNumber)
}
}