70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
|
|
//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)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|