Files
llm-intelligence/scripts/fetch_tencent_catalog_test.go
phamnazage-jpg 77e6610fd2
Some checks failed
CI / test (push) Has been cancelled
chore: prepare repository for publishing
2026-05-13 14:42:45 +08:00

99 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build llm_script
package main
import (
"bytes"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseTencentCatalogExtractsPlansAndModels(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "tencent_token_plan_sample.txt"))
if err != nil {
t.Fatalf("读取样例失败: %v", err)
}
catalog, err := parseTencentCatalog(string(raw))
if err != nil {
t.Fatalf("parseTencentCatalog 失败: %v", err)
}
if catalog.UpdatedAt != "2026-04-27 17:18:02" {
t.Fatalf("更新时间错误: %q", catalog.UpdatedAt)
}
if len(catalog.Plans) != 8 {
t.Fatalf("期望 8 个套餐,实际 %d", len(catalog.Plans))
}
if len(catalog.Models) != 11 {
t.Fatalf("期望 11 个模型,实际 %d", len(catalog.Models))
}
firstPlan := catalog.Plans[0]
if firstPlan.Series != "通用 Token Plan" {
t.Fatalf("套餐系列错误: %q", firstPlan.Series)
}
if firstPlan.Tier != "Lite" {
t.Fatalf("套餐档位错误: %q", firstPlan.Tier)
}
if firstPlan.Price != "39元/月" {
t.Fatalf("套餐价格错误: %q", firstPlan.Price)
}
if firstPlan.Quota != "3500万 Tokens" {
t.Fatalf("套餐额度错误: %q", firstPlan.Quota)
}
lastModel := catalog.Models[len(catalog.Models)-1]
if lastModel.Name != "Hy3 preview" {
t.Fatalf("最后一个模型错误: %q", lastModel.Name)
}
if lastModel.ModelID != "hy3-preview" {
t.Fatalf("最后一个模型 ID 错误: %q", lastModel.ModelID)
}
if lastModel.ContextLength != 262144 {
t.Fatalf("Hy3 preview 上下文长度错误: %d", lastModel.ContextLength)
}
}
func TestRunTencentCatalogDryRunPrintsSummary(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "tencent_token_plan_sample.txt"))
if err != nil {
t.Fatalf("读取样例失败: %v", err)
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write([]byte("<html><body><main><pre>" + string(raw) + "</pre></main></body></html>"))
}))
defer server.Close()
var out bytes.Buffer
err = runTencentCatalog(fetchTencentCatalogConfig{
URL: server.URL,
DryRun: true,
Timeout: defaultTencentCatalogTimeout,
}, server.Client(), &out)
if err != nil {
t.Fatalf("runTencentCatalog 失败: %v", err)
}
output := out.String()
for _, want := range []string{
"source=tencent-public-catalog",
"plans=8",
"models=11",
"series=Hy Token Plan:4,通用 Token Plan:4",
"updated_at=2026-04-27 17:18:02",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}