feat(platform): harden telemetry pipeline and unify Semi UI workspaces
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/yutongmqtt"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/telemetry"
|
||||
)
|
||||
|
||||
func TestRealtimeKVFieldsFromGB32960ParsedDomains(t *testing.T) {
|
||||
@@ -157,6 +159,37 @@ func TestBuildFieldsEnvelopeCopiesSourceMetadata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildFieldsEnvelopeKeepsYutongJSONNumberMileage(t *testing.T) {
|
||||
env, err := yutongmqtt.ParseMessage(
|
||||
"yutong",
|
||||
"/ytforward/shln/1",
|
||||
[]byte(`{"device":"LMRKH9AC2R1004106","time":"2026-07-17 11:50:13.021","data":{"LATITUDE":30.466027,"LONGITUDE":103.96096,"METER_SPEED":0,"TOTAL_MILEAGE":77081000}}`),
|
||||
1784260213051,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseMessage() error = %v", err)
|
||||
}
|
||||
if !EnsureParsedFields(&env) {
|
||||
t.Fatal("EnsureParsedFields() should compute ingress fields")
|
||||
}
|
||||
fieldsEnv, ok := BuildFieldsEnvelope(env)
|
||||
if !ok {
|
||||
t.Fatal("BuildFieldsEnvelope() should emit Yutong fields")
|
||||
}
|
||||
for _, field := range []string{
|
||||
"yutong_mqtt.data.total_mileage",
|
||||
"yutong_mqtt.root.data.total_mileage",
|
||||
} {
|
||||
if got := fieldsEnv.Fields[field]; got != "77081000" {
|
||||
t.Fatalf("%s = %#v, want 77081000", field, got)
|
||||
}
|
||||
}
|
||||
mileageKM, found := telemetry.TotalMileageKM(fieldsEnv.Protocol, fieldsEnv.Fields)
|
||||
if !found || mileageKM != 77081 {
|
||||
t.Fatalf("TotalMileageKM() = %.3f, %v; want 77081, true", mileageKM, found)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildFieldsEnvelopeDropsNonPositiveTotalMileage(t *testing.T) {
|
||||
fieldsEnv, ok := BuildFieldsEnvelope(envelope.FrameEnvelope{
|
||||
Protocol: envelope.ProtocolJT808,
|
||||
|
||||
@@ -825,12 +825,27 @@ func positiveNumber(value any) bool {
|
||||
return typed > 0
|
||||
case int:
|
||||
return typed > 0
|
||||
case int8:
|
||||
return typed > 0
|
||||
case int16:
|
||||
return typed > 0
|
||||
case int32:
|
||||
return typed > 0
|
||||
case int64:
|
||||
return typed > 0
|
||||
case uint:
|
||||
return typed > 0
|
||||
case uint8:
|
||||
return typed > 0
|
||||
case uint16:
|
||||
return typed > 0
|
||||
case uint32:
|
||||
return typed > 0
|
||||
case uint64:
|
||||
return typed > 0
|
||||
case json.Number:
|
||||
parsed, err := typed.Float64()
|
||||
return err == nil && parsed > 0
|
||||
case string:
|
||||
parsed, err := strconv.ParseFloat(strings.TrimSpace(typed), 64)
|
||||
return err == nil && parsed > 0
|
||||
|
||||
Reference in New Issue
Block a user