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.
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
//go:build llm_script
|
||
|
||
package main
|
||
|
||
import (
|
||
"bytes"
|
||
"os"
|
||
"path/filepath"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestParseCUCloudCatalogBuildsRecords(t *testing.T) {
|
||
raw, err := os.ReadFile(filepath.Join("testdata", "cucloud_catalog_sample.txt"))
|
||
if err != nil {
|
||
t.Fatalf("读取 fixture 失败: %v", err)
|
||
}
|
||
|
||
records, err := parseCUCloudCatalog(string(raw))
|
||
if err != nil {
|
||
t.Fatalf("parseCUCloudCatalog 返回错误: %v", err)
|
||
}
|
||
if len(records) != 2 {
|
||
t.Fatalf("期望 2 条联通云目录记录,实际 %d", len(records))
|
||
}
|
||
if records[0].CatalogCode != "cucloud-aicp-platform" {
|
||
t.Fatalf("首条 catalogCode 错误: %q", records[0].CatalogCode)
|
||
}
|
||
if records[1].CatalogCode != "cucloud-ai-app-platform" {
|
||
t.Fatalf("第二条 catalogCode 错误: %q", records[1].CatalogCode)
|
||
}
|
||
}
|
||
|
||
func TestRunCUCloudCatalogImportDryRunPrintsSummary(t *testing.T) {
|
||
var out bytes.Buffer
|
||
err := runCUCloudCatalogImport(catalogVerificationImportConfig{
|
||
URL: defaultCUCloudCatalogURL,
|
||
Fixture: filepath.Join("testdata", "cucloud_catalog_sample.txt"),
|
||
DryRun: true,
|
||
}, nil, &out)
|
||
if err != nil {
|
||
t.Fatalf("runCUCloudCatalogImport 返回错误: %v", err)
|
||
}
|
||
output := out.String()
|
||
for _, want := range []string{
|
||
"source=cucloud-catalog-import",
|
||
"entries=2",
|
||
"dry_run=true",
|
||
} {
|
||
if !strings.Contains(output, want) {
|
||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||
}
|
||
}
|
||
}
|