Files
llm-intelligence/scripts/import_bytedance_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

70 lines
2.1 KiB
Go
Raw 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 TestParseBytedanceSubscriptionBuildsPlans(t *testing.T) {
pricingRaw, err := os.ReadFile(filepath.Join("testdata", "bytedance_coding_plan_sample.txt"))
if err != nil {
t.Fatalf("读取 pricing fixture 失败: %v", err)
}
noticeRaw, err := os.ReadFile(filepath.Join("testdata", "bytedance_coding_plan_notice_sample.txt"))
if err != nil {
t.Fatalf("读取 notice fixture 失败: %v", err)
}
plans, err := parseBytedanceSubscriptionCatalog(string(pricingRaw), string(noticeRaw))
if err != nil {
t.Fatalf("parseBytedanceSubscriptionCatalog 返回错误: %v", err)
}
if len(plans) != 4 {
t.Fatalf("期望 4 条火山套餐记录,实际 %d", len(plans))
}
if plans[0].PlanCode != "bytedance-coding-plan-lite" {
t.Fatalf("首条标准套餐 planCode 错误: %q", plans[0].PlanCode)
}
if plans[1].PlanCode != "bytedance-coding-plan-lite-first-month" {
t.Fatalf("首条活动套餐 planCode 错误: %q", plans[1].PlanCode)
}
if plans[1].ListPrice != 9.9 {
t.Fatalf("Lite 首月活动价错误: %v", plans[1].ListPrice)
}
if !strings.Contains(plans[1].Notes, "每日 10:30") {
t.Fatalf("活动套餐备注缺少限量说明: %q", plans[1].Notes)
}
if plans[3].QuotaValue != 90000 {
t.Fatalf("Pro 月额度错误: %d", plans[3].QuotaValue)
}
}
func TestRunBytedanceSubscriptionImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runBytedanceSubscriptionImport(bytedanceSubscriptionImportConfig{
PricingFixture: filepath.Join("testdata", "bytedance_coding_plan_sample.txt"),
NoticeFixture: filepath.Join("testdata", "bytedance_coding_plan_notice_sample.txt"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runBytedanceSubscriptionImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=bytedance-subscription-import",
"plans=4",
"provider=ByteDance",
"operator=ByteDance Volcano",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}