Files
llm-intelligence/scripts/import_aliyun_subscription_test.go
phamnazage-jpg 958245537a feat(imports): add real pricing and subscription collectors
Add plan catalog and subscription schema support, seed baselines, and real importers for core domestic subscriptions plus stable official pricing sources.

This commit also hardens the shared fetch layers so the importers can support live collection and database writes instead of relying on manual placeholders alone.
2026-05-15 22:32:57 +08:00

72 lines
2.0 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 TestParseAliyunSubscriptionBuildsPlans(t *testing.T) {
tokenRaw, err := os.ReadFile(filepath.Join("testdata", "aliyun_token_plan_sample.txt"))
if err != nil {
t.Fatalf("读取 token fixture 失败: %v", err)
}
codingRaw, err := os.ReadFile(filepath.Join("testdata", "aliyun_coding_plan_sample.txt"))
if err != nil {
t.Fatalf("读取 coding fixture 失败: %v", err)
}
plans, err := parseAliyunSubscriptionCatalog(string(tokenRaw), string(codingRaw))
if err != nil {
t.Fatalf("parseAliyunSubscriptionCatalog 失败: %v", err)
}
if len(plans) != 5 {
t.Fatalf("期望 5 条阿里云套餐记录,实际 %d", len(plans))
}
if plans[0].PlanCode != "aliyun-token-plan-standard-seat" {
t.Fatalf("首条 planCode 错误: %q", plans[0].PlanCode)
}
if plans[0].ListPrice != 198 {
t.Fatalf("标准坐席价格错误: %v", plans[0].ListPrice)
}
if plans[3].PlanCode != "aliyun-token-plan-shared-pack" {
t.Fatalf("共享包 planCode 错误: %q", plans[3].PlanCode)
}
if plans[4].PlanCode != "aliyun-coding-plan-pro" {
t.Fatalf("Coding Plan Pro planCode 错误: %q", plans[4].PlanCode)
}
if !strings.Contains(plans[4].Notes, "活动已结束") {
t.Fatalf("Coding Plan 备注缺少活动说明: %q", plans[4].Notes)
}
}
func TestRunAliyunSubscriptionImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runAliyunSubscriptionImport(aliyunSubscriptionImportConfig{
TokenFixture: filepath.Join("testdata", "aliyun_token_plan_sample.txt"),
CodingFixture: filepath.Join("testdata", "aliyun_coding_plan_sample.txt"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runAliyunSubscriptionImport 失败: %v", err)
}
output := out.String()
for _, want := range []string{
"source=aliyun-subscription-import",
"plans=5",
"provider=Alibaba",
"operator=Alibaba Bailian",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}