refactor(go): make daily mileage vin only

This commit is contained in:
lingniu
2026-07-02 21:02:02 +08:00
parent b23ae3410c
commit bec6326103
8 changed files with 43 additions and 106 deletions

View File

@@ -28,8 +28,8 @@ func TestSamplesFromEnvelopeDerivesDailyMileageSample(t *testing.T) {
if len(samples) != 1 {
t.Fatalf("sample count = %d", len(samples))
}
if samples[0].VehicleKey != "LNBVIN00000000001" {
t.Fatalf("vehicle key = %q", samples[0].VehicleKey)
if samples[0].VIN != "LNBVIN00000000001" {
t.Fatalf("vin = %q", samples[0].VIN)
}
if samples[0].TotalMileageKM != 10241.2 {
t.Fatalf("total mileage = %v", samples[0].TotalMileageKM)
@@ -39,7 +39,7 @@ func TestSamplesFromEnvelopeDerivesDailyMileageSample(t *testing.T) {
}
}
func TestSamplesFromEnvelopeUsesVehicleKeyWhenVINIsMissing(t *testing.T) {
func TestSamplesFromEnvelopeSkipsMissingVIN(t *testing.T) {
loc := time.FixedZone("Asia/Shanghai", 8*3600)
samples, err := SamplesFromEnvelope(envelope.FrameEnvelope{
Protocol: envelope.ProtocolJT808,
@@ -52,18 +52,12 @@ func TestSamplesFromEnvelopeUsesVehicleKeyWhenVINIsMissing(t *testing.T) {
if err != nil {
t.Fatalf("SamplesFromEnvelope() error = %v", err)
}
if len(samples) != 1 {
t.Fatalf("sample count = %d", len(samples))
}
if samples[0].VehicleKey != "JT808:13307811254" {
t.Fatalf("vehicle key = %q", samples[0].VehicleKey)
}
if samples[0].VIN != "" {
t.Fatalf("vin should stay empty for unresolved JT808 identity, got %q", samples[0].VIN)
if len(samples) != 0 {
t.Fatalf("expected no samples without VIN, got %#v", samples)
}
}
func TestSamplesFromEnvelopeSkipsMissingVehicleKeyOrMileage(t *testing.T) {
func TestSamplesFromEnvelopeSkipsMissingVINOrMileage(t *testing.T) {
samples, err := SamplesFromEnvelope(envelope.FrameEnvelope{
Protocol: envelope.ProtocolJT808,
Fields: map[string]any{envelope.FieldTotalMileageKM: 1.2},
@@ -72,7 +66,7 @@ func TestSamplesFromEnvelopeSkipsMissingVehicleKeyOrMileage(t *testing.T) {
t.Fatalf("SamplesFromEnvelope() error = %v", err)
}
if len(samples) != 0 {
t.Fatalf("expected no samples without vehicle key, got %#v", samples)
t.Fatalf("expected no samples without VIN, got %#v", samples)
}
samples, err = SamplesFromEnvelope(envelope.FrameEnvelope{
@@ -127,8 +121,8 @@ func TestWriterEnsuresSchemaAndUpsertsDailyMileage(t *testing.T) {
if !strings.Contains(exec.calls[0].query, "CREATE TABLE IF NOT EXISTS vehicle_daily_mileage") {
t.Fatalf("unexpected schema sql: %s", exec.calls[0].query)
}
if !strings.Contains(exec.calls[0].query, "vehicle_key") {
t.Fatalf("schema should include vehicle_key: %s", exec.calls[0].query)
if strings.Contains(exec.calls[0].query, "vehicle_key") {
t.Fatalf("schema should not include vehicle_key: %s", exec.calls[0].query)
}
if len(exec.calls) != 2 {
t.Fatalf("exec calls = %d", len(exec.calls))
@@ -143,7 +137,7 @@ func TestWriterEnsuresSchemaAndUpsertsDailyMileage(t *testing.T) {
t.Fatalf("upsert should ignore legacy zero first mileage: %s", exec.calls[1].query)
}
if got := exec.calls[1].args[0]; got != "LNBVIN00000000002" {
t.Fatalf("first upsert arg should be vehicle_key, got %#v", got)
t.Fatalf("first upsert arg should be vin, got %#v", got)
}
}