|
- package router
-
- import (
- "net/http"
- "strings"
- "testing"
-
- "github.com/gin-gonic/gin"
- "github.com/stretchr/testify/require"
- )
-
- func TestKlingAipingNativeRoutesDoNotFallThroughToOpenAIVideoRoutes(t *testing.T) {
- gin.SetMode(gin.TestMode)
- r := gin.New()
- SetVideoRouter(r)
-
- requireHandlerContains(t, r, http.MethodPost, "/v1/videos/text2video", "KlingAipingNativeTaskSubmit")
- requireHandlerContains(t, r, http.MethodGet, "/v1/videos/text2video/:task_id", "KlingAipingNativeTaskFetch")
- requireHandlerContains(t, r, http.MethodGet, "/v1/videos/text2video", "KlingAipingNativeTaskList")
- requireHandlerContains(t, r, http.MethodPost, "/v1/videos/video-extend", "KlingAipingNativeTaskSubmit")
- requireHandlerContains(t, r, http.MethodGet, "/v1/videos/video-extend/:task_id", "KlingAipingNativeTaskFetch")
- requireHandlerContains(t, r, http.MethodGet, "/v1/videos/video-extend", "KlingAipingNativeTaskList")
- requireHandlerContains(t, r, http.MethodGet, "/v1/general/advanced-presets-elements", "KlingAipingNativeProxy")
- requireHandlerContains(t, r, http.MethodPost, "/v1/general/delete-advanced-elements", "KlingAipingNativeProxy")
- requireHandlerContains(t, r, http.MethodPost, "/v1/general/delete-voices", "KlingAipingNativeProxy")
-
- requireHandlerContains(t, r, http.MethodPost, "/v1/videos", "RelayTask")
- requireHandlerContains(t, r, http.MethodGet, "/v1/videos/:task_id", "RelayTaskFetch")
- }
-
- func requireHandlerContains(t *testing.T, r *gin.Engine, method, path, want string) {
- t.Helper()
- for _, route := range r.Routes() {
- if route.Method != method || route.Path != path {
- continue
- }
- require.Truef(t, strings.Contains(route.Handler, want), "handler for %s %s = %s, want containing %s", method, path, route.Handler, want)
- return
- }
- t.Fatalf("route not found: %s %s", method, path)
- }
|