feat: 算力引擎 Go 后端核心(new-api)
- 统一 OpenAI 兼容 /v1 中继 + 渠道/额度/令牌/流水 - 各领域包:relay 模型网关、model 数据层、controller 管理 API
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/setting/system_setting"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetStatusReturnsEffectiveOIDCDisplayName(t *testing.T) {
|
||||
settings := system_setting.GetOIDCSettings()
|
||||
originalDisplayName := settings.DisplayName
|
||||
originalOptionMap := common.OptionMap
|
||||
t.Cleanup(func() {
|
||||
settings.DisplayName = originalDisplayName
|
||||
common.OptionMap = originalOptionMap
|
||||
})
|
||||
common.OptionMap = map[string]string{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
displayName string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "custom name is trimmed",
|
||||
displayName: " Acme SSO ",
|
||||
want: "Acme SSO",
|
||||
},
|
||||
{
|
||||
name: "whitespace-only name falls back",
|
||||
displayName: " ",
|
||||
want: "OIDC",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
settings.DisplayName = tt.displayName
|
||||
response := httptest.NewRecorder()
|
||||
context, _ := gin.CreateTestContext(response)
|
||||
context.Request = httptest.NewRequest(http.MethodGet, "/api/status", nil)
|
||||
|
||||
GetStatus(context)
|
||||
|
||||
var payload struct {
|
||||
Success bool `json:"success"`
|
||||
Data map[string]any `json:"data"`
|
||||
}
|
||||
require.NoError(t, common.Unmarshal(response.Body.Bytes(), &payload))
|
||||
require.True(t, payload.Success)
|
||||
assert.Equal(t, tt.want, payload.Data["oidc_display_name"])
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user