Files
llm-intelligence/scripts/import_qwen_pricing_test.go

62 lines
1.6 KiB
Go
Raw Normal View History

//go:build llm_script
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseQwenPricingCatalogBuildsRecords(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "qwen_pricing_sample.txt"))
if err != nil {
t.Fatalf("读取 fixture 失败: %v", err)
}
records, err := parseQwenPricingCatalog(string(raw))
if err != nil {
t.Fatalf("parseQwenPricingCatalog 返回错误: %v", err)
}
if len(records) != 4 {
t.Fatalf("期望 4 条通义千问价格记录,实际 %d", len(records))
}
if records[0].ModelID != "qwen-qwen-max" {
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
}
if records[1].InputPrice != 0.8 || records[1].OutputPrice != 2 {
t.Fatalf("qwen-plus 定价错误: %v / %v", records[1].InputPrice, records[1].OutputPrice)
}
if records[2].Modality != "multimodal" {
t.Fatalf("qwen-vl-max modality 错误: %q", records[2].Modality)
}
if records[3].ProviderName != "Qwen" {
t.Fatalf("provider 错误: %q", records[3].ProviderName)
}
}
func TestRunQwenPricingImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runQwenPricingImport(qwenPricingImportConfig{
URL: defaultQwenPricingURL,
Fixture: filepath.Join("testdata", "qwen_pricing_sample.txt"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runQwenPricingImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=qwen-pricing-import",
"models=4",
"operator=DashScope",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}