feat(platform): keep canonical source summary slots

This commit is contained in:
lingniu
2026-07-04 07:54:38 +08:00
parent 422ac684ed
commit 1d691306db
6 changed files with 72 additions and 5 deletions

View File

@@ -83,3 +83,22 @@ func TestVehicleServiceSummaryCountsProtocolOnlineByProtocolSlot(t *testing.T) {
t.Fatalf("GB32960 online count must use GB32960 source status only, got %+v", gb32960)
}
}
func TestCompleteProtocolStatsIncludesCanonicalSlots(t *testing.T) {
stats := completeProtocolStats([]ProtocolStat{{Protocol: "JT808", Online: 2, Total: 5}})
byProtocol := map[string]ProtocolStat{}
for _, stat := range stats {
byProtocol[stat.Protocol] = stat
}
for _, protocol := range canonicalVehicleProtocols {
if _, ok := byProtocol[protocol]; !ok {
t.Fatalf("canonical protocol %s should be present, got %+v", protocol, stats)
}
}
if byProtocol["JT808"].Online != 2 || byProtocol["JT808"].Total != 5 {
t.Fatalf("existing protocol stats should be preserved, got %+v", byProtocol["JT808"])
}
if byProtocol["GB32960"].Online != 0 || byProtocol["GB32960"].Total != 0 {
t.Fatalf("missing canonical protocol should be exposed as zero slot, got %+v", byProtocol["GB32960"])
}
}