//go:build llm_script package main import ( "bytes" "os" "path/filepath" "strings" "testing" ) func TestParseCTYunSubscriptionBuildsPlans(t *testing.T) { codingRaw, err := os.ReadFile(filepath.Join("testdata", "ctyun_coding_plan_sample.txt")) if err != nil { t.Fatalf("读取 coding fixture 失败: %v", err) } tokenRaw, err := os.ReadFile(filepath.Join("testdata", "ctyun_token_plan_sample.txt")) if err != nil { t.Fatalf("读取 token fixture 失败: %v", err) } plans, err := parseCTYunSubscriptionCatalog(string(codingRaw), string(tokenRaw)) if err != nil { t.Fatalf("parseCTYunSubscriptionCatalog 失败: %v", err) } if len(plans) != 6 { t.Fatalf("期望 6 条天翼云套餐记录,实际 %d", len(plans)) } if plans[0].PlanCode != "ctyun-coding-plan-lite-monthly" { t.Fatalf("首条 coding planCode 错误: %q", plans[0].PlanCode) } if plans[0].ListPrice != 49 { t.Fatalf("GLM Lite 月价错误: %v", plans[0].ListPrice) } if plans[3].PlanCode != "ctyun-token-plan-basic" { t.Fatalf("首条 token planCode 错误: %q", plans[3].PlanCode) } if plans[3].QuotaValue != 15000000 || plans[3].PriceUnit != "CNY/month" || plans[3].QuotaUnit != "tokens/month" { t.Fatalf("基础版 token plan 解析错误: %+v", plans[3]) } if plans[len(plans)-1].PlanCode != "ctyun-token-plan-flagship" { t.Fatalf("末条 token planCode 错误: %q", plans[len(plans)-1].PlanCode) } } func TestParseCTYunTokenPlanLegacyLayout(t *testing.T) { legacy := `Token Plan Lite1500万Tokens包 支持模型:GLM5 39 .90 元/个 Token Plan 轻享包1000万Tokens包 支持模型:Deepseek v3.2 9 .90 元/个` records, err := parseCTYunTokenPlan(legacy, "2026-05-18") if err != nil { t.Fatalf("legacy token plan 解析失败: %v", err) } if len(records) != 2 { t.Fatalf("期望 2 条 legacy token 记录,实际 %d", len(records)) } if records[0].PlanCode != "ctyun-token-plan-lite" || records[0].PriceUnit != "CNY/pack" || records[0].QuotaUnit != "tokens/pack" { t.Fatalf("legacy Lite 解析错误: %+v", records[0]) } if records[1].PlanCode != "ctyun-token-plan-starter" { t.Fatalf("legacy 轻享包解析错误: %+v", records[1]) } } func TestRunCTYunSubscriptionImportDryRunPrintsSummary(t *testing.T) { var out bytes.Buffer err := runCTYunSubscriptionImport(ctyunSubscriptionImportConfig{ CodingFixture: filepath.Join("testdata", "ctyun_coding_plan_sample.txt"), TokenFixture: filepath.Join("testdata", "ctyun_token_plan_sample.txt"), DryRun: true, }, nil, &out) if err != nil { t.Fatalf("runCTYunSubscriptionImport 失败: %v", err) } output := out.String() for _, want := range []string{ "source=ctyun-subscription-import", "plans=6", "provider=Telecom", "operator=CTYun", "dry_run=true", } { if !strings.Contains(output, want) { t.Fatalf("输出缺少 %q,实际: %q", want, output) } } }