70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
|
|
//go:build llm_script
|
|||
|
|
|
|||
|
|
package main
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"bytes"
|
|||
|
|
"os"
|
|||
|
|
"path/filepath"
|
|||
|
|
"strings"
|
|||
|
|
"testing"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
func TestParseBaiduSubscriptionBuildsPlans(t *testing.T) {
|
|||
|
|
codingRaw, err := os.ReadFile(filepath.Join("testdata", "baidu_coding_plan_sample.txt"))
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("读取 coding fixture 失败: %v", err)
|
|||
|
|
}
|
|||
|
|
tokenRaw, err := os.ReadFile(filepath.Join("testdata", "baidu_token_benefit_pack_sample.txt"))
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("读取 token fixture 失败: %v", err)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
plans, err := parseBaiduSubscriptionCatalog(string(codingRaw), string(tokenRaw))
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("parseBaiduSubscriptionCatalog 失败: %v", err)
|
|||
|
|
}
|
|||
|
|
if len(plans) != 7 {
|
|||
|
|
t.Fatalf("期望 7 条百度套餐记录,实际 %d", len(plans))
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if plans[0].PlanCode != "baidu-coding-plan-lite" {
|
|||
|
|
t.Fatalf("Lite planCode 错误: %q", plans[0].PlanCode)
|
|||
|
|
}
|
|||
|
|
if plans[1].PlanCode != "baidu-coding-plan-pro" {
|
|||
|
|
t.Fatalf("Pro planCode 错误: %q", plans[1].PlanCode)
|
|||
|
|
}
|
|||
|
|
last := plans[len(plans)-1]
|
|||
|
|
if last.PlanCode != "baidu-token-benefit-pack-800000" {
|
|||
|
|
t.Fatalf("末条 token 福利包 planCode 错误: %q", last.PlanCode)
|
|||
|
|
}
|
|||
|
|
if !strings.Contains(last.Notes, "首购优惠价") {
|
|||
|
|
t.Fatalf("token 福利包备注缺少首购优惠说明: %q", last.Notes)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func TestRunBaiduSubscriptionImportDryRunPrintsSummary(t *testing.T) {
|
|||
|
|
var out bytes.Buffer
|
|||
|
|
err := runBaiduSubscriptionImport(baiduSubscriptionImportConfig{
|
|||
|
|
CodingFixture: filepath.Join("testdata", "baidu_coding_plan_sample.txt"),
|
|||
|
|
TokenFixture: filepath.Join("testdata", "baidu_token_benefit_pack_sample.txt"),
|
|||
|
|
DryRun: true,
|
|||
|
|
}, nil, &out)
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("runBaiduSubscriptionImport 失败: %v", err)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
output := out.String()
|
|||
|
|
for _, want := range []string{
|
|||
|
|
"source=baidu-subscription-import",
|
|||
|
|
"plans=7",
|
|||
|
|
"provider=Baidu",
|
|||
|
|
"operator=Baidu Qianfan",
|
|||
|
|
"dry_run=true",
|
|||
|
|
} {
|
|||
|
|
if !strings.Contains(output, want) {
|
|||
|
|
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|