fix(platform): degrade vehicles with missing sources
This commit is contained in:
@@ -117,8 +117,8 @@ func TestHandlerVehicleCoverageFiltersServiceStatus(t *testing.T) {
|
||||
if !strings.Contains(rec.Body.String(), "LB9A32A24R0LS1426") {
|
||||
t.Fatalf("degraded coverage should include partially online multi-source vehicle: %s", rec.Body.String())
|
||||
}
|
||||
if strings.Contains(rec.Body.String(), "LMRKH9AC2R1004087") {
|
||||
t.Fatalf("degraded coverage should exclude healthy single-source vehicle: %s", rec.Body.String())
|
||||
if !strings.Contains(rec.Body.String(), "LMRKH9AC2R1004087") {
|
||||
t.Fatalf("degraded coverage should include online single-source vehicle that misses canonical sources: %s", rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +138,30 @@ func TestHandlerVehicleCoverageFiltersMissingProtocol(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerVehicleCoverageTreatsMissingCanonicalSourceAsDegraded(t *testing.T) {
|
||||
handler := NewHandler(NewService(NewMockStore()))
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/vehicles/coverage?limit=10&missingProtocol=YUTONG_MQTT&online=online", nil)
|
||||
handler.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Data Page[VehicleCoverageRow] `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("response JSON should decode: %v body=%s", err, rec.Body.String())
|
||||
}
|
||||
if len(body.Data.Items) == 0 {
|
||||
t.Fatalf("missing source query should return online vehicles with missing canonical source: %s", rec.Body.String())
|
||||
}
|
||||
for _, row := range body.Data.Items {
|
||||
if row.ServiceStatus == nil || row.ServiceStatus.Status != "degraded" {
|
||||
t.Fatalf("missing canonical source should degrade vehicle service, got row=%+v body=%s", row, rec.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerVehicleCoverageSummary(t *testing.T) {
|
||||
handler := NewHandler(NewService(NewMockStore()))
|
||||
rec := httptest.NewRecorder()
|
||||
@@ -607,8 +631,8 @@ func TestHandlerVehicleRealtimeFiltersServiceStatus(t *testing.T) {
|
||||
if !strings.Contains(rec.Body.String(), "LB9A32A24R0LS1426") {
|
||||
t.Fatalf("degraded realtime should include partially online vehicle: %s", rec.Body.String())
|
||||
}
|
||||
if strings.Contains(rec.Body.String(), "LNXNEGRR7SR318212") {
|
||||
t.Fatalf("degraded realtime should exclude healthy single-source vehicle: %s", rec.Body.String())
|
||||
if !strings.Contains(rec.Body.String(), "LNXNEGRR7SR318212") {
|
||||
t.Fatalf("degraded realtime should include online single-source vehicle that misses canonical sources: %s", rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user