feat(import): extend CTYun subscription collector

- ctyun_subscription_lib.go: extend CTYun subscription data extraction
- import_ctyun_subscription_test.go: update tests for CTYun
- ctyun_token_plan_sample.txt: updated test fixture
This commit is contained in:
phamnazage-jpg
2026-05-22 07:33:38 +08:00
parent 0de4402a11
commit 8d1312203f
3 changed files with 251 additions and 43 deletions

View File

@@ -24,8 +24,8 @@ func TestParseCTYunSubscriptionBuildsPlans(t *testing.T) {
if err != nil {
t.Fatalf("parseCTYunSubscriptionCatalog 失败: %v", err)
}
if len(plans) != 9 {
t.Fatalf("期望 9 条天翼云套餐记录,实际 %d", len(plans))
if len(plans) != 6 {
t.Fatalf("期望 6 条天翼云套餐记录,实际 %d", len(plans))
}
if plans[0].PlanCode != "ctyun-coding-plan-lite-monthly" {
@@ -34,14 +34,40 @@ func TestParseCTYunSubscriptionBuildsPlans(t *testing.T) {
if plans[0].ListPrice != 49 {
t.Fatalf("GLM Lite 月价错误: %v", plans[0].ListPrice)
}
if plans[3].PlanCode != "ctyun-token-plan-lite" {
if plans[3].PlanCode != "ctyun-token-plan-basic" {
t.Fatalf("首条 token planCode 错误: %q", plans[3].PlanCode)
}
if plans[len(plans)-1].PlanCode != "ctyun-token-plan-vip" {
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{
@@ -56,7 +82,7 @@ func TestRunCTYunSubscriptionImportDryRunPrintsSummary(t *testing.T) {
output := out.String()
for _, want := range []string{
"source=ctyun-subscription-import",
"plans=9",
"plans=6",
"provider=Telecom",
"operator=CTYun",
"dry_run=true",