refactor(go): keep realtime mysql tables core only
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
)
|
||||
|
||||
func TestSnapshotWriterEnsuresSchemaAndUpsertsParsedJSON(t *testing.T) {
|
||||
func TestSnapshotWriterEnsuresSchemaAndUpsertsCoreSnapshot(t *testing.T) {
|
||||
exec := &recordingSnapshotExec{}
|
||||
writer := NewSnapshotWriter(exec)
|
||||
|
||||
@@ -46,22 +46,26 @@ func TestSnapshotWriterEnsuresSchemaAndUpsertsParsedJSON(t *testing.T) {
|
||||
if !strings.Contains(exec.calls[1].query, "CREATE TABLE IF NOT EXISTS vehicle_realtime_location") {
|
||||
t.Fatalf("location schema query = %s", exec.calls[1].query)
|
||||
}
|
||||
for _, call := range exec.calls[:2] {
|
||||
if strings.Contains(call.query, "parsed_json") || strings.Contains(call.query, "fields_json") {
|
||||
t.Fatalf("realtime schema should not contain json payload columns: %s", call.query)
|
||||
}
|
||||
}
|
||||
upsert := exec.calls[2]
|
||||
if !strings.Contains(upsert.query, "ON DUPLICATE KEY UPDATE") {
|
||||
t.Fatalf("upsert query = %s", upsert.query)
|
||||
}
|
||||
if strings.Contains(upsert.query, "parsed_json") || strings.Contains(upsert.query, "fields_json") {
|
||||
t.Fatalf("snapshot upsert should not write json payload columns: %s", upsert.query)
|
||||
}
|
||||
if got, want := upsert.args[0], "GB32960"; got != want {
|
||||
t.Fatalf("protocol arg = %#v, want %q", got, want)
|
||||
}
|
||||
if got, want := upsert.args[1], "VIN001"; got != want {
|
||||
t.Fatalf("vehicle key arg = %#v, want %q", got, want)
|
||||
}
|
||||
parsedJSON, ok := upsert.args[10].(string)
|
||||
if !ok {
|
||||
t.Fatalf("parsed_json arg type = %T", upsert.args[10])
|
||||
}
|
||||
if !strings.Contains(parsedJSON, "gd_fc_vendor_tlv") || !strings.Contains(parsedJSON, "vehicle") {
|
||||
t.Fatalf("parsed_json should contain original and vendor parsed data: %s", parsedJSON)
|
||||
if len(upsert.args) != 12 {
|
||||
t.Fatalf("snapshot upsert args = %d, want 12", len(upsert.args))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +108,9 @@ func TestSnapshotWriterUpsertsRealtimeLocationWhenCoordinatesExist(t *testing.T)
|
||||
if !strings.Contains(locationUpsert.query, "INSERT INTO vehicle_realtime_location") {
|
||||
t.Fatalf("location upsert query = %s", locationUpsert.query)
|
||||
}
|
||||
if strings.Contains(locationUpsert.query, "fields_json") {
|
||||
t.Fatalf("location upsert should not write fields_json: %s", locationUpsert.query)
|
||||
}
|
||||
if got, want := locationUpsert.args[0], "JT808"; got != want {
|
||||
t.Fatalf("protocol arg = %#v, want %q", got, want)
|
||||
}
|
||||
@@ -125,6 +132,9 @@ func TestSnapshotWriterUpsertsRealtimeLocationWhenCoordinatesExist(t *testing.T)
|
||||
if got, want := locationUpsert.args[14], 88.0; got != want {
|
||||
t.Fatalf("soc arg = %#v, want %v", got, want)
|
||||
}
|
||||
if len(locationUpsert.args) != 21 {
|
||||
t.Fatalf("location upsert args = %d, want 21", len(locationUpsert.args))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSnapshotWriterBackfillsPlateFromBindingByVIN(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user