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.
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
//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) != 9 {
|
||
t.Fatalf("期望 9 条天翼云套餐记录,实际 %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-lite" {
|
||
t.Fatalf("首条 token planCode 错误: %q", plans[3].PlanCode)
|
||
}
|
||
if plans[len(plans)-1].PlanCode != "ctyun-token-plan-vip" {
|
||
t.Fatalf("末条 token planCode 错误: %q", plans[len(plans)-1].PlanCode)
|
||
}
|
||
}
|
||
|
||
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=9",
|
||
"provider=Telecom",
|
||
"operator=CTYun",
|
||
"dry_run=true",
|
||
} {
|
||
if !strings.Contains(output, want) {
|
||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||
}
|
||
}
|
||
}
|