mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-05-12 17:16:32 +08:00
- Included `/v1/images` in AI API path prefixes. - Introduced tests to validate `/v1/images/generations` and `/v1/images/edits` as AI API paths.
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package logging
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestGinLogrusRecoveryRepanicsErrAbortHandler(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
engine := gin.New()
|
|
engine.Use(GinLogrusRecovery())
|
|
engine.GET("/abort", func(c *gin.Context) {
|
|
panic(http.ErrAbortHandler)
|
|
})
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/abort", nil)
|
|
recorder := httptest.NewRecorder()
|
|
|
|
defer func() {
|
|
recovered := recover()
|
|
if recovered == nil {
|
|
t.Fatalf("expected panic, got nil")
|
|
}
|
|
err, ok := recovered.(error)
|
|
if !ok {
|
|
t.Fatalf("expected error panic, got %T", recovered)
|
|
}
|
|
if !errors.Is(err, http.ErrAbortHandler) {
|
|
t.Fatalf("expected ErrAbortHandler, got %v", err)
|
|
}
|
|
if err != http.ErrAbortHandler {
|
|
t.Fatalf("expected exact ErrAbortHandler sentinel, got %v", err)
|
|
}
|
|
}()
|
|
|
|
engine.ServeHTTP(recorder, req)
|
|
}
|
|
|
|
func TestGinLogrusRecoveryHandlesRegularPanic(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
engine := gin.New()
|
|
engine.Use(GinLogrusRecovery())
|
|
engine.GET("/panic", func(c *gin.Context) {
|
|
panic("boom")
|
|
})
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/panic", nil)
|
|
recorder := httptest.NewRecorder()
|
|
|
|
engine.ServeHTTP(recorder, req)
|
|
if recorder.Code != http.StatusInternalServerError {
|
|
t.Fatalf("expected 500, got %d", recorder.Code)
|
|
}
|
|
}
|
|
|
|
func TestIsAIAPIPathIncludesImages(t *testing.T) {
|
|
if !isAIAPIPath("/v1/images/generations") {
|
|
t.Fatalf("expected /v1/images/generations to be treated as AI API path")
|
|
}
|
|
if !isAIAPIPath("/v1/images/edits") {
|
|
t.Fatalf("expected /v1/images/edits to be treated as AI API path")
|
|
}
|
|
}
|