Files
xk-ai-agent/internal/llm/openai_compat_url_test.go
2026-08-15 17:05:22 +08:00

29 lines
1.0 KiB
Go

package llm
import "testing"
func TestResolveChatCompletionsURL(t *testing.T) {
cases := []struct {
in string
want string
}{
// DB 完整路径:不可再拼
{"https://api.deepseek.com/v1/chat/completions", "https://api.deepseek.com/v1/chat/completions"},
{"https://api.deepseek.com/v1/chat/completions/", "https://api.deepseek.com/v1/chat/completions"},
// yaml 仅 host
{"https://api.deepseek.com", "https://api.deepseek.com/v1/chat/completions"},
{"https://api.deepseek.com/", "https://api.deepseek.com/v1/chat/completions"},
// 已到 /v1
{"https://api.deepseek.com/v1", "https://api.deepseek.com/v1/chat/completions"},
// OpenAI 常见写法
{"https://api.openai.com/v1", "https://api.openai.com/v1/chat/completions"},
{"https://api.openai.com/v1/chat/completions", "https://api.openai.com/v1/chat/completions"},
}
for _, tc := range cases {
got := ResolveChatCompletionsURL(tc.in)
if got != tc.want {
t.Errorf("ResolveChatCompletionsURL(%q) = %q, want %q", tc.in, got, tc.want)
}
}
}