28e53d90fc
- 统一 OpenAI 兼容 /v1 中继 + 渠道/额度/令牌/流水 - 各领域包:relay 模型网关、model 数据层、controller 管理 API
35 lines
873 B
Go
35 lines
873 B
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestUpdateOptionRejectsNegativeClaudeDefaultMaxTokens(t *testing.T) {
|
|
response := httptest.NewRecorder()
|
|
context, _ := gin.CreateTestContext(response)
|
|
context.Request = httptest.NewRequest(
|
|
http.MethodPut,
|
|
"/api/option/",
|
|
strings.NewReader(`{"key":"claude.default_max_tokens","value":"{\"default\":-1}"}`),
|
|
)
|
|
|
|
UpdateOption(context)
|
|
|
|
assert.Equal(t, http.StatusOK, response.Code)
|
|
var payload struct {
|
|
Success bool `json:"success"`
|
|
Message string `json:"message"`
|
|
}
|
|
require.NoError(t, common.Unmarshal(response.Body.Bytes(), &payload))
|
|
assert.False(t, payload.Success)
|
|
assert.Contains(t, payload.Message, "-1")
|
|
}
|