forked from niuniu/llm-intelligence
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.
This commit is contained in:
55
scripts/import_siliconflow_pricing_test.go
Normal file
55
scripts/import_siliconflow_pricing_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
//go:build llm_script
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseSiliconFlowPricingCatalogBuildsRecords(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("testdata", "siliconflow_pricing_sample.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("读取 fixture 失败: %v", err)
|
||||
}
|
||||
|
||||
records, err := parseSiliconFlowPricingCatalog(string(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("parseSiliconFlowPricingCatalog 返回错误: %v", err)
|
||||
}
|
||||
if len(records) != 5 {
|
||||
t.Fatalf("期望 5 条硅基流动价格记录,实际 %d", len(records))
|
||||
}
|
||||
if records[0].ProviderName != "Qwen" {
|
||||
t.Fatalf("Qwen provider 识别错误: %q", records[0].ProviderName)
|
||||
}
|
||||
if !records[4].IsFree {
|
||||
t.Fatalf("免费模型应标记为 free_tier")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunSiliconFlowPricingImportDryRunPrintsSummary(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
err := runSiliconFlowPricingImport(siliconFlowPricingImportConfig{
|
||||
URL: defaultSiliconFlowPricingURL,
|
||||
Fixture: filepath.Join("testdata", "siliconflow_pricing_sample.txt"),
|
||||
DryRun: true,
|
||||
}, nil, &out)
|
||||
if err != nil {
|
||||
t.Fatalf("runSiliconFlowPricingImport 返回错误: %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"source=siliconflow-pricing-import",
|
||||
"models=5",
|
||||
"operator=SiliconCloud",
|
||||
"dry_run=true",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user