36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package realtime
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestOpenAPIHandlerDocumentsRealtimeSnapshotAndLocation(t *testing.T) {
|
|
request := httptest.NewRequest(http.MethodGet, "/openapi.json", nil)
|
|
response := httptest.NewRecorder()
|
|
|
|
NewOpenAPIHandler().ServeHTTP(response, request)
|
|
|
|
if response.Code != http.StatusOK {
|
|
t.Fatalf("status = %d body=%s", response.Code, response.Body.String())
|
|
}
|
|
body := response.Body.String()
|
|
for _, want := range []string{`"/api/realtime/snapshots"`, `"/api/realtime/locations"`, `"vehicle_realtime_snapshot"`, `"vehicle_realtime_location"`} {
|
|
if !strings.Contains(body, want) {
|
|
t.Fatalf("openapi missing %s: %s", want, body)
|
|
}
|
|
}
|
|
for _, removed := range []string{`"/api/realtime/kv"`, `"vehicle_realtime_kv"`, `"Realtime KV API"`} {
|
|
if strings.Contains(body, removed) {
|
|
t.Fatalf("openapi should not expose removed MySQL realtime kv API %s: %s", removed, body)
|
|
}
|
|
}
|
|
for _, want := range []string{`"includeTotal"`, `默认不执行 COUNT(*)`, `total 默认表示本页返回条数`} {
|
|
if !strings.Contains(body, want) {
|
|
t.Fatalf("openapi should document lightweight total semantics, missing %s: %s", want, body)
|
|
}
|
|
}
|
|
}
|