mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-03 06:52:13 +08:00
- Apply InboundEndpointMiddleware to all gateway route groups - Replace normalizedOpenAIInboundEndpoint/normalizedOpenAIUpstreamEndpoint and normalizedGatewayInboundEndpoint/normalizedGatewayUpstreamEndpoint with GetInboundEndpoint/GetUpstreamEndpoint - Remove 4 old constants and 4 old normalization functions (-70 lines) - Migrate existing endpoint normalization test to new API Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestOpenAIUpstreamEndpoint_ViaGetUpstreamEndpoint verifies that the
|
|
// unified GetUpstreamEndpoint helper produces the same results as the
|
|
// former normalizedOpenAIUpstreamEndpoint for OpenAI platform requests.
|
|
func TestOpenAIUpstreamEndpoint_ViaGetUpstreamEndpoint(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
want string
|
|
}{
|
|
{
|
|
name: "responses root maps to responses upstream",
|
|
path: "/v1/responses",
|
|
want: EndpointResponses,
|
|
},
|
|
{
|
|
name: "responses compact keeps compact suffix",
|
|
path: "/openai/v1/responses/compact",
|
|
want: "/v1/responses/compact",
|
|
},
|
|
{
|
|
name: "responses nested suffix preserved",
|
|
path: "/openai/v1/responses/compact/detail",
|
|
want: "/v1/responses/compact/detail",
|
|
},
|
|
{
|
|
name: "non responses path uses platform fallback",
|
|
path: "/v1/messages",
|
|
want: EndpointResponses,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
rec := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(rec)
|
|
c.Request = httptest.NewRequest(http.MethodPost, tt.path, nil)
|
|
|
|
got := GetUpstreamEndpoint(c, service.PlatformOpenAI)
|
|
require.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|