fix(stats): elect trusted mileage source
This commit is contained in:
@@ -187,19 +187,23 @@ func TestWriterEnsuresSchemaAndUpsertsDailyMileage(t *testing.T) {
|
||||
if strings.Contains(exec.calls[0].query, "KEY idx_vin (vin)") {
|
||||
t.Fatalf("daily mileage table should not keep redundant vin index covered by the primary key: %s", exec.calls[0].query)
|
||||
}
|
||||
if len(exec.calls) != 2 {
|
||||
if len(exec.calls) != 5 {
|
||||
t.Fatalf("exec calls = %d", len(exec.calls))
|
||||
}
|
||||
if !strings.Contains(exec.calls[1].query, "ON DUPLICATE KEY UPDATE") {
|
||||
t.Fatalf("unexpected upsert sql: %s", exec.calls[1].query)
|
||||
upsertCall := exec.calls[4]
|
||||
if !strings.Contains(upsertCall.query, "ON DUPLICATE KEY UPDATE") {
|
||||
t.Fatalf("unexpected upsert sql: %s", upsertCall.query)
|
||||
}
|
||||
if strings.Contains(exec.calls[1].query, "metric_key") || strings.Contains(exec.calls[1].query, "metric_unit") {
|
||||
t.Fatalf("daily mileage upsert should not use generic metric columns: %s", exec.calls[1].query)
|
||||
if strings.Contains(upsertCall.query, "metric_key") || strings.Contains(upsertCall.query, "metric_unit") {
|
||||
t.Fatalf("daily mileage upsert should not use generic metric columns: %s", upsertCall.query)
|
||||
}
|
||||
if !strings.Contains(exec.calls[1].query, "first_total_mileage_km <= 0") {
|
||||
t.Fatalf("upsert should ignore legacy zero first mileage: %s", exec.calls[1].query)
|
||||
if !strings.Contains(upsertCall.query, "first_total_mileage_km <= 0") {
|
||||
t.Fatalf("upsert should ignore legacy zero first mileage: %s", upsertCall.query)
|
||||
}
|
||||
if got := exec.calls[1].args[0]; got != "LNBVIN00000000002" {
|
||||
if !strings.Contains(upsertCall.query, "trusted_source_key") {
|
||||
t.Fatalf("upsert should track trusted source: %s", upsertCall.query)
|
||||
}
|
||||
if got := upsertCall.args[0]; got != "LNBVIN00000000002" {
|
||||
t.Fatalf("first upsert arg should be vin, got %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user