fix(go): collapse gb32960 auxiliary snapshot

This commit is contained in:
lingniu
2026-07-03 13:17:31 +08:00
parent 112b02e8c5
commit a96490618c
2 changed files with 68 additions and 2 deletions

View File

@@ -271,6 +271,53 @@ func TestRepositoryCollapsesGB32960VendorStackFragmentsIntoSingleRealtimeSummary
}
}
func TestRepositoryReplacesGB32960VendorAuxiliarySubsystemsWithLatestState(t *testing.T) {
repo, closeFn := newTestRepository(t)
defer closeFn()
ctx := context.Background()
for i, voltage := range []float64{372, 348} {
if err := repo.Update(ctx, envelope.FrameEnvelope{
Protocol: envelope.ProtocolGB32960,
VIN: "VIN001",
EventTimeMS: int64(1000 + i),
ReceivedAtMS: int64(1100 + i),
Parsed: map[string]any{
"data_units": []any{
map[string]any{
"type": "0x31",
"name": "gd_fc_auxiliary",
"value": map[string]any{
"subsystem_count": 1,
"subsystems": []any{map[string]any{
"air_compressor_motor_voltage_v": voltage,
"water_pump_voltage_v": voltage,
}},
},
},
},
},
}); err != nil {
t.Fatalf("Update() error = %v", err)
}
}
realtimeRaw, err := repo.GetRealtimeRaw(ctx, "VIN001", envelope.ProtocolGB32960)
if err != nil {
t.Fatalf("GetRealtimeRaw() error = %v", err)
}
unit := realtimeRaw["data_units"].([]any)[0].(map[string]any)
value := unit["value"].(map[string]any)
subsystems := value["subsystems"].([]any)
if len(subsystems) != 1 {
t.Fatalf("auxiliary subsystems should keep current state, not append historical frames: %#v", subsystems)
}
subsystem := subsystems[0].(map[string]any)
if subsystem["air_compressor_motor_voltage_v"] != float64(348) {
t.Fatalf("auxiliary subsystem should keep latest values: %#v", subsystem)
}
}
func TestRepositoryWritesRealtimeKVHashes(t *testing.T) {
repo, closeFn := newTestRepository(t)
defer closeFn()