Files
llm-intelligence/scripts/import_tencent_subscription_test.go
2026-05-13 14:42:45 +08:00

91 lines
2.4 KiB
Go
Raw Permalink 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"
"os"
"path/filepath"
"strings"
"testing"
)
func TestBuildSubscriptionPlansFromCatalog(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)
}
plans := buildSubscriptionPlans(catalog, defaultTencentCatalogURL)
if len(plans) != 8 {
t.Fatalf("期望 8 条套餐记录,实际 %d", len(plans))
}
first := plans[0]
if first.ProviderName != "Tencent" {
t.Fatalf("provider 错误: %q", first.ProviderName)
}
if first.OperatorName != "Tencent Cloud" {
t.Fatalf("operator 错误: %q", first.OperatorName)
}
if first.PlanFamily != "token_plan" {
t.Fatalf("plan family 错误: %q", first.PlanFamily)
}
if first.PlanCode != "token-plan-lite" {
t.Fatalf("plan code 错误: %q", first.PlanCode)
}
if first.ListPrice != 39 {
t.Fatalf("list price 错误: %v", first.ListPrice)
}
if first.QuotaValue != 35000000 {
t.Fatalf("quota value 错误: %d", first.QuotaValue)
}
if !strings.Contains(first.ModelScope, "\"glm-5\"") {
t.Fatalf("model_scope 缺少 glm-5: %q", first.ModelScope)
}
if first.PublishedAt != "2026-04-27 17:18:02" {
t.Fatalf("published_at 错误: %q", first.PublishedAt)
}
last := plans[len(plans)-1]
if last.PlanFamily != "token_plan" {
t.Fatalf("Hy Token Plan family 错误: %q", last.PlanFamily)
}
if last.PlanCode != "hy-token-plan-max" {
t.Fatalf("Hy Token Plan code 错误: %q", last.PlanCode)
}
if last.ContextWindow != 262144 {
t.Fatalf("Hy Token Plan context 错误: %d", last.ContextWindow)
}
}
func TestRunTencentSubscriptionImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runTencentSubscriptionImport(importTencentSubscriptionConfig{
Fixture: filepath.Join("testdata", "tencent_token_plan_sample.txt"),
DryRun: true,
URL: defaultTencentCatalogURL,
}, nil, &out)
if err != nil {
t.Fatalf("runTencentSubscriptionImport 失败: %v", err)
}
output := out.String()
for _, want := range []string{
"source=tencent-subscription-import",
"plans=8",
"provider=Tencent",
"operator=Tencent Cloud",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}