64 lines
2.3 KiB
Go
64 lines
2.3 KiB
Go
package collector
|
|
|
|
import (
|
|
"bee/audit/internal/schema"
|
|
"testing"
|
|
)
|
|
|
|
func TestFinalizeSnapshotFiltersComponentsWithoutRequiredSerials(t *testing.T) {
|
|
collectedAt := "2026-03-15T12:00:00Z"
|
|
present := true
|
|
status := statusOK
|
|
serial := "SN-1"
|
|
|
|
snap := schema.HardwareSnapshot{
|
|
Memory: []schema.HardwareMemory{
|
|
{Present: &present, SerialNumber: &serial, HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
{Present: &present, HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
},
|
|
Storage: []schema.HardwareStorage{
|
|
{SerialNumber: &serial, HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
{HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
},
|
|
PowerSupplies: []schema.HardwarePowerSupply{
|
|
{SerialNumber: &serial, HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
{HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
},
|
|
}
|
|
|
|
finalizeSnapshot(&snap, collectedAt)
|
|
|
|
if len(snap.Memory) != 1 || snap.Memory[0].StatusCheckedAt == nil || *snap.Memory[0].StatusCheckedAt != collectedAt {
|
|
t.Fatalf("memory finalize mismatch: %+v", snap.Memory)
|
|
}
|
|
if len(snap.Storage) != 1 || snap.Storage[0].StatusCheckedAt == nil || *snap.Storage[0].StatusCheckedAt != collectedAt {
|
|
t.Fatalf("storage finalize mismatch: %+v", snap.Storage)
|
|
}
|
|
if len(snap.PowerSupplies) != 1 || snap.PowerSupplies[0].StatusCheckedAt == nil || *snap.PowerSupplies[0].StatusCheckedAt != collectedAt {
|
|
t.Fatalf("psu finalize mismatch: %+v", snap.PowerSupplies)
|
|
}
|
|
}
|
|
|
|
func TestFinalizeSnapshotPreservesDuplicateSerials(t *testing.T) {
|
|
collectedAt := "2026-03-15T12:00:00Z"
|
|
status := statusOK
|
|
model := "Device"
|
|
serial := "DUPLICATE"
|
|
|
|
snap := schema.HardwareSnapshot{
|
|
Storage: []schema.HardwareStorage{
|
|
{Model: &model, SerialNumber: &serial, HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
{Model: &model, SerialNumber: &serial, HardwareComponentStatus: schema.HardwareComponentStatus{Status: &status}},
|
|
},
|
|
}
|
|
|
|
finalizeSnapshot(&snap, collectedAt)
|
|
|
|
if got := *snap.Storage[0].SerialNumber; got != serial {
|
|
t.Fatalf("first serial changed: %q", got)
|
|
}
|
|
if got := *snap.Storage[1].SerialNumber; got != serial {
|
|
t.Fatalf("duplicate serial should stay unchanged: %q", got)
|
|
}
|
|
}
|