Files
llm-intelligence/scripts/import_coreshub_pricing_test.go
phamnazage-jpg 0de4402a11 feat(import): add CoreHub pricing collector and importer
- coreshub_pricing_lib.go: CoreHub pricing data extraction and parsing
- import_coreshub_pricing.go: importer with dry_run support
- import_coreshub_pricing_test.go: unit tests for importer
- coreshub_pricing_sample.txt: test fixture
2026-05-22 07:33:13 +08:00

65 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build llm_script
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseCoresHubPricingCatalogBuildsRecords(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "coreshub_pricing_sample.txt"))
if err != nil {
t.Fatalf("读取 fixture 失败: %v", err)
}
records, err := parseCoresHubPricingCatalog(string(raw))
if err != nil {
t.Fatalf("parseCoresHubPricingCatalog 返回错误: %v", err)
}
if len(records) != 8 {
t.Fatalf("期望 8 条 CoresHub 价格记录,实际 %d", len(records))
}
if records[0].ModelID != "coreshub-deepseek-r1-distill-qwen-1-5b" {
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
}
if !records[0].IsFree || records[0].InputPrice != 0 || records[0].OutputPrice != 0 {
t.Fatalf("免费模型解析错误: %+v", records[0])
}
if records[3].InputPrice != 0.2 || records[3].OutputPrice != 0.2 {
t.Fatalf("千 token 单价换算错误: %+v", records[3])
}
if records[6].InputPrice != 2 || records[6].OutputPrice != 8 {
t.Fatalf("DeepSeek-V3 价格错误: %+v", records[6])
}
if records[7].InputPrice != 4 || records[7].OutputPrice != 16 {
t.Fatalf("DeepSeek-R1 价格错误: %+v", records[7])
}
}
func TestRunCoresHubPricingImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runCoresHubPricingImport(coreshubPricingImportConfig{
URL: defaultCoresHubPricingURL,
Fixture: filepath.Join("testdata", "coreshub_pricing_sample.txt"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runCoresHubPricingImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=coreshub-pricing-import",
"models=8",
"operator=CoresHub",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}