Files
lingniu-vehicle-ingest/go/vehicle-gateway/cmd/mileage-baseline-repair/main_test.go
T
lingniu d6b957dfc8 feat: sync vehicle monitoring and accumulated platform updates
Add monitoring metrics, numeric sorting, report-time display, vehicle number labels, and map layout fixes. Include accumulated mileage, hydrogen, OneOS authentication, open platform, ingestion, deployment, and UI updates.

Exclude temporary files, generated reports, and credentials. Validate frontend 632 tests and production build, API packages, vehicle-map tests, and release installer tests. Gateway suite has one pre-existing date-sensitive identity throttling test failure reproduced on the parent commit.
2026-10-26 18:05:59 +08:00

54 lines
2.0 KiB
Go

package main
import (
"context"
"testing"
"github.com/DATA-DOG/go-sqlmock"
)
func TestCanonicalRepairSourceRequiresVerifiedRegistryIdentity(t *testing.T) {
for _, tc := range []struct {
name, key, code, kind, want string
missing, wantError bool
}{
{name: "platform", key: "JT808:41456413939@117.132.196.192", code: "guangan_beidou", kind: "PLATFORM", want: "JT808:41456413939@PLATFORM:guangan_beidou"},
{name: "direct", key: "JT808:41456413939@117.132.196.192", kind: "DIRECT", want: "JT808:41456413939@DIRECT"},
{name: "unknown", key: "JT808:41456413939@117.132.196.192", kind: "UNKNOWN", wantError: true},
{name: "missing", key: "JT808:41456413939@117.132.196.192", missing: true, wantError: true},
{name: "platform-without-code", key: "JT808:41456413939@117.132.196.192", kind: "PLATFORM", wantError: true},
} {
t.Run(tc.name, func(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatal(err)
}
defer db.Close()
rows := sqlmock.NewRows([]string{"code", "kind"})
if !tc.missing {
rows.AddRow(tc.code, tc.kind)
}
mock.ExpectQuery("SELECT COALESCE").WithArgs("JT808", "117.132.196.192").WillReturnRows(rows)
got, err := canonicalRepairSource(context.Background(), db, "JT808", tc.key)
if (err != nil) != tc.wantError || got != tc.want {
t.Fatalf("got=%q err=%v want=%q wantError=%v", got, err, tc.want, tc.wantError)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Fatal(err)
}
})
}
}
func TestCanonicalRepairSourceKeepsIndependentCounters(t *testing.T) {
for _, key := range []string{"JT808:terminal-a@PLATFORM:g7s", "JT808:terminal-b@PLATFORM:g7s", "JT808:terminal-a@PLATFORM:dongfang_beidou"} {
got, err := canonicalRepairSource(context.Background(), nil, "JT808", key)
if err != nil || got != key {
t.Fatalf("independent identity changed: %s %v", got, err)
}
}
if _, err := canonicalRepairSource(context.Background(), nil, "GB32960", "GB32960:vin@PLATFORM:g7s"); err == nil {
t.Fatal("alias repair must not silently change other protocol rules")
}
}