- internal/gemini/ → internal/adapters/openai/ (renamed package to openai) - internal/pexels/ → internal/adapters/pexels/ - internal/config/ → internal/infra/config/ - internal/database/ → internal/infra/database/ - internal/locale/ → internal/infra/locale/ - internal/middleware/ → internal/infra/middleware/ - internal/server/ → internal/infra/server/ All import paths and call sites updated accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package middleware_test
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/food-ai/backend/internal/infra/middleware"
|
|
)
|
|
|
|
func TestRecovery_NoPanic(t *testing.T) {
|
|
handler := middleware.Recovery(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
}))
|
|
|
|
req := httptest.NewRequest("GET", "/", nil)
|
|
rr := httptest.NewRecorder()
|
|
|
|
handler.ServeHTTP(rr, req)
|
|
if rr.Code != http.StatusOK {
|
|
t.Errorf("expected 200, got %d", rr.Code)
|
|
}
|
|
}
|
|
|
|
func TestRecovery_CatchesPanic(t *testing.T) {
|
|
handler := middleware.Recovery(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
panic("test panic")
|
|
}))
|
|
|
|
req := httptest.NewRequest("GET", "/", nil)
|
|
rr := httptest.NewRecorder()
|
|
|
|
handler.ServeHTTP(rr, req)
|
|
if rr.Code != http.StatusInternalServerError {
|
|
t.Errorf("expected 500, got %d", rr.Code)
|
|
}
|
|
}
|
|
|
|
func TestRecovery_CatchesPanicWithError(t *testing.T) {
|
|
handler := middleware.Recovery(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
panic(42)
|
|
}))
|
|
|
|
req := httptest.NewRequest("GET", "/", nil)
|
|
rr := httptest.NewRecorder()
|
|
|
|
handler.ServeHTTP(rr, req)
|
|
if rr.Code != http.StatusInternalServerError {
|
|
t.Errorf("expected 500, got %d", rr.Code)
|
|
}
|
|
}
|