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.
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
//go:build llm_script
|
||
|
||
package main
|
||
|
||
import (
|
||
"bytes"
|
||
"os"
|
||
"path/filepath"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestParseUCloudPricingCatalogBuildsRecords(t *testing.T) {
|
||
raw, err := os.ReadFile(filepath.Join("testdata", "ucloud_pricing_sample.txt"))
|
||
if err != nil {
|
||
t.Fatalf("读取 fixture 失败: %v", err)
|
||
}
|
||
|
||
records, err := parseUCloudPricingCatalog(string(raw))
|
||
if err != nil {
|
||
t.Fatalf("parseUCloudPricingCatalog 返回错误: %v", err)
|
||
}
|
||
if len(records) != 5 {
|
||
t.Fatalf("期望 5 条 UCloud 价格记录,实际 %d", len(records))
|
||
}
|
||
if records[0].InputPrice != 0.1 {
|
||
t.Fatalf("gpt-4o-mini 输入价换算错误: %v", records[0].InputPrice)
|
||
}
|
||
if records[2].OutputPrice != 16 {
|
||
t.Fatalf("DeepSeek-R1 输出价错误: %v", records[2].OutputPrice)
|
||
}
|
||
}
|
||
|
||
func TestRunUCloudPricingImportDryRunPrintsSummary(t *testing.T) {
|
||
var out bytes.Buffer
|
||
err := runUCloudPricingImport(ucloudPricingImportConfig{
|
||
URL: defaultUCloudPricingURL,
|
||
Fixture: filepath.Join("testdata", "ucloud_pricing_sample.txt"),
|
||
DryRun: true,
|
||
}, nil, &out)
|
||
if err != nil {
|
||
t.Fatalf("runUCloudPricingImport 返回错误: %v", err)
|
||
}
|
||
output := out.String()
|
||
for _, want := range []string{
|
||
"source=ucloud-pricing-import",
|
||
"models=5",
|
||
"operator=UModelVerse",
|
||
"dry_run=true",
|
||
} {
|
||
if !strings.Contains(output, want) {
|
||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||
}
|
||
}
|
||
}
|