Files
llm-intelligence/scripts/import_youdao_pricing_test.go

59 lines
1.5 KiB
Go
Raw Normal View History

//go:build llm_script
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseYoudaoPricingCatalogBuildsRecords(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "youdao_pricing_sample.txt"))
if err != nil {
t.Fatalf("读取 fixture 失败: %v", err)
}
records, err := parseYoudaoPricingCatalog(string(raw))
if err != nil {
t.Fatalf("parseYoudaoPricingCatalog 返回错误: %v", err)
}
if len(records) != 5 {
t.Fatalf("期望 5 条有道价格记录,实际 %d", len(records))
}
if records[0].ModelID != "youdao-deepseek-v4-flash" {
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
}
if records[2].ProviderName != "Moonshot AI" {
t.Fatalf("Kimi provider 归一化错误: %q", records[2].ProviderName)
}
if records[4].ContextLength != 128000 {
t.Fatalf("GLM-5 上下文长度错误: %d", records[4].ContextLength)
}
}
func TestRunYoudaoPricingImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runYoudaoPricingImport(youdaoPricingImportConfig{
URL: defaultYoudaoPricingURL,
Fixture: filepath.Join("testdata", "youdao_pricing_sample.txt"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runYoudaoPricingImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=youdao-pricing-import",
"models=5",
"operator=Youdao Zhiyun MaaS",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}