62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
//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)
|
||
}
|
||
}
|
||
}
|