mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 08:55:28 +08:00
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package openai
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func TestGetModelRouteDirectAndAlias(t *testing.T) {
|
|
h := &openAITestSurface{}
|
|
r := chi.NewRouter()
|
|
registerOpenAITestRoutes(r, h)
|
|
|
|
t.Run("direct", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/deepseek-v4-flash", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
})
|
|
|
|
t.Run("direct_nothinking", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/deepseek-v4-flash-nothinking", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
})
|
|
|
|
t.Run("direct_expert", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/deepseek-v4-pro", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
})
|
|
|
|
t.Run("direct_vision", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/deepseek-v4-vision", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
})
|
|
|
|
t.Run("alias", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/gpt-4.1", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected 200 for alias, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
})
|
|
|
|
t.Run("alias_nothinking", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/claude-sonnet-4-6-nothinking", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected 200 for nothinking alias, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestGetModelRouteNotFound(t *testing.T) {
|
|
h := &openAITestSurface{}
|
|
r := chi.NewRouter()
|
|
registerOpenAITestRoutes(r, h)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/v1/models/not-exists", nil)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusNotFound {
|
|
t.Fatalf("expected 404, got %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
}
|