package router import ( "net/http" "net/http/httptest" "testing" "hfb_sys/backend/internal/config" "hfb_sys/backend/internal/database" "go.uber.org/zap" ) func testConfig() config.Config { return config.Config{AppEnv: "test", JWTSecret: "test-secret"} } func TestHealthRoutesSeparateLivenessAndReadiness(t *testing.T) { engine := New(testConfig(), Dependencies{}, zap.NewNop()) for _, tt := range []struct { path string wantStatus int }{ {path: "/health", wantStatus: http.StatusOK}, {path: "/health/ready", wantStatus: http.StatusServiceUnavailable}, {path: "/api/health", wantStatus: http.StatusServiceUnavailable}, } { recorder := httptest.NewRecorder() request := httptest.NewRequest(http.MethodGet, tt.path, nil) engine.ServeHTTP(recorder, request) if recorder.Code != tt.wantStatus { t.Fatalf("GET %s status = %d, want %d; body=%s", tt.path, recorder.Code, tt.wantStatus, recorder.Body.String()) } } } func TestExtractedAdminRoutesRemainRegisteredWithoutDuplicates(t *testing.T) { db := database.NewTestDB() engine := New(testConfig(), Dependencies{DB: db}, zap.NewNop()) routes := engine.Routes() registered := make(map[string]struct{}, len(routes)) for _, route := range routes { key := route.Method + " " + route.Path if _, exists := registered[key]; exists { t.Fatalf("duplicate route: %s", key) } registered[key] = struct{}{} } for _, key := range []string{ "GET /api/admin/crash/products", "GET /api/admin/mohong/products", "POST /api/admin/chats/qrcodes/batch", "PUT /api/admin/chat-support-groups/:id/members", "PUT /api/admin/roles/:id/permissions", "PUT /api/admin/admin-users/:id/password", "POST /api/admin/announcements/:id/publish", "GET /api/distribution/sites/:id/listings", "GET /api/distribution/sites/:id/wallet", } { if _, exists := registered[key]; !exists { t.Errorf("missing route after extraction: %s", key) } } }