mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-15 23:22:59 +08:00
test: cover endpoint wildcard edge cases
This commit is contained in:
@@ -232,6 +232,24 @@ func TestInboundEndpointMiddleware_WildcardRoutes(t *testing.T) {
|
||||
requestPath: "/backend-api/codex/responses/compact",
|
||||
want: EndpointResponsesCompact,
|
||||
},
|
||||
{
|
||||
name: "v1 responses wildcard route, non-compact subpath request",
|
||||
routePath: "/v1/responses/*subpath",
|
||||
requestPath: "/v1/responses/foo",
|
||||
want: EndpointResponses,
|
||||
},
|
||||
{
|
||||
name: "bare responses wildcard route, non-compact subpath request",
|
||||
routePath: "/responses/*subpath",
|
||||
requestPath: "/responses/foo",
|
||||
want: EndpointResponses,
|
||||
},
|
||||
{
|
||||
name: "codex direct wildcard route, non-compact subpath request",
|
||||
routePath: "/backend-api/codex/responses/*subpath",
|
||||
requestPath: "/backend-api/codex/responses/foo",
|
||||
want: EndpointResponses,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -254,6 +272,29 @@ func TestInboundEndpointMiddleware_WildcardRoutes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestInboundEndpointMiddleware_GeminiWildcardRoute verifies that a Gemini
|
||||
// wildcard route (e.g. "/v1beta/models/*modelAction", used to capture the
|
||||
// ":generateContent"-style action suffix embedded in the path) is normalized
|
||||
// to EndpointGeminiModels via InboundEndpointMiddleware, using the same real
|
||||
// Gin routing path as TestInboundEndpointMiddleware_WildcardRoutes above.
|
||||
func TestInboundEndpointMiddleware_GeminiWildcardRoute(t *testing.T) {
|
||||
router := gin.New()
|
||||
router.Use(InboundEndpointMiddleware())
|
||||
|
||||
var captured string
|
||||
router.POST("/v1beta/models/*modelAction", func(c *gin.Context) {
|
||||
captured = GetInboundEndpoint(c)
|
||||
c.Status(http.StatusOK)
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/v1beta/models/gemini-2.5-pro:generateContent", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
router.ServeHTTP(rec, req)
|
||||
|
||||
require.Equal(t, http.StatusOK, rec.Code)
|
||||
require.Equal(t, EndpointGeminiModels, captured)
|
||||
}
|
||||
|
||||
// TestGetInboundEndpoint_FallbackWildcardRouteWithoutMiddleware verifies
|
||||
// that when InboundEndpointMiddleware did NOT run (so no value is stored
|
||||
// in gin.Context), the GetInboundEndpoint fallback path still prefers
|
||||
|
||||
Reference in New Issue
Block a user