feat(go): reuse parsed fields across projections
This commit is contained in:
@@ -646,6 +646,37 @@ func TestRepositoryOnlineStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepositoryUsesEnvelopeParsedFieldsForRealtimeKV(t *testing.T) {
|
||||
repo, closeFn := newTestRepository(t)
|
||||
defer closeFn()
|
||||
ctx := context.Background()
|
||||
|
||||
if err := repo.Update(ctx, envelope.FrameEnvelope{
|
||||
Protocol: envelope.ProtocolJT808,
|
||||
VIN: "VIN001",
|
||||
EventTimeMS: 1000,
|
||||
ReceivedAtMS: 1100,
|
||||
MessageID: "0x0200",
|
||||
Parsed: map[string]any{
|
||||
"location": map[string]any{"speed_kmh": 99},
|
||||
},
|
||||
ParsedFields: map[string]any{
|
||||
"jt808.location.speed_kmh": "12.3",
|
||||
},
|
||||
Fields: map[string]any{envelope.FieldSpeedKMH: 12.3},
|
||||
}); err != nil {
|
||||
t.Fatalf("Update() error = %v", err)
|
||||
}
|
||||
|
||||
values, err := repo.client.HGetAll(ctx, realtimeKVValuesKey(envelope.ProtocolJT808, "VIN001")).Result()
|
||||
if err != nil {
|
||||
t.Fatalf("HGetAll() error = %v", err)
|
||||
}
|
||||
if got, want := values["jt808.location.speed_kmh"], "12.3"; got != want {
|
||||
t.Fatalf("speed kv = %#v, want %q; all=%#v", got, want, values)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepositorySkipsFramesWithoutVIN(t *testing.T) {
|
||||
repo, closeFn := newTestRepository(t)
|
||||
defer closeFn()
|
||||
|
||||
Reference in New Issue
Block a user