fix(go): preserve sparse realtime location fields

This commit is contained in:
lingniu
2026-07-03 10:56:38 +08:00
parent 9c212815ef
commit 0fa5343ab3
2 changed files with 24 additions and 7 deletions

View File

@@ -223,6 +223,23 @@ func TestRealtimeUpsertsDoNotOverwriteWithOlderEventTime(t *testing.T) {
}
}
func TestRealtimeLocationUpsertKeepsExistingSparseFieldsWhenMQTTOnlySendsCoordinates(t *testing.T) {
for _, column := range []string{
"speed_kmh",
"total_mileage_km",
"soc_percent",
"altitude_m",
"direction_deg",
"alarm_flag",
"status_flag",
} {
want := column + " = IF(VALUES(event_time) IS NOT NULL AND (vehicle_realtime_location.event_time IS NULL OR VALUES(event_time) >= vehicle_realtime_location.event_time), COALESCE(VALUES(" + column + "), " + column + "), " + column + ")"
if !strings.Contains(upsertRealtimeLocationSQL, want) {
t.Fatalf("location upsert should keep existing %s when incoming sparse MQTT frame omits it; missing:\n%s\nin:\n%s", column, want, upsertRealtimeLocationSQL)
}
}
}
func TestSnapshotWriterBackfillsPlateFromBindingByVIN(t *testing.T) {
exec := &recordingSnapshotExec{}
resolver := &recordingPlateResolver{plate: "沪A12345"}