Files
llm-intelligence/scripts/import_youdao_pricing_test.go

62 lines
1.6 KiB
Go
Raw 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 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) != 10 {
t.Fatalf("期望 10 条有道价格记录,实际 %d", len(records))
}
if records[0].ModelID != "youdao-deepseek-v4-flash" {
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
}
if records[5].ProviderName != "Moonshot AI" {
t.Fatalf("Kimi provider 归一化错误: %q", records[5].ProviderName)
}
if records[8].ProviderName != "Zhipu AI" {
t.Fatalf("智谱 provider 归一化错误: %q", records[8].ProviderName)
}
if records[8].ContextLength != 200000 {
t.Fatalf("GLM-5 上下文长度错误: %d", records[8].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=10",
"operator=Youdao Zhiyun MaaS",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}