Files
llm-intelligence/scripts/import_huawei_maas_pricing_test.go

69 lines
2.2 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 TestParseHuaweiMaaSPricingCatalogBuildsRecords(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "huawei_maas_pricing_sample.json"))
if err != nil {
t.Fatalf("读取 fixture 失败: %v", err)
}
records, err := parseHuaweiMaaSPricingCatalog(string(raw))
if err != nil {
t.Fatalf("parseHuaweiMaaSPricingCatalog 返回错误: %v", err)
}
if len(records) != 3 {
t.Fatalf("期望 3 条华为云 MaaS 价格记录,实际 %d", len(records))
}
if records[0].ModelID != "huawei-maas-deepseek-v4-pro" {
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
}
recordMap := make(map[string]officialPricingRecord, len(records))
for _, record := range records {
recordMap[record.ModelID] = record
}
if recordMap["huawei-maas-deepseek-v4-pro"].ProviderName != "DeepSeek" {
t.Fatalf("deepseek provider 归一化错误: %q", recordMap["huawei-maas-deepseek-v4-pro"].ProviderName)
}
if recordMap["huawei-maas-qwen3-32b"].ProviderName != "Qwen" {
t.Fatalf("Qwen provider 归一化错误: %q", recordMap["huawei-maas-qwen3-32b"].ProviderName)
}
if recordMap["huawei-maas-qwen3-32b"].OutputPrice != 0.008 {
t.Fatalf("qwen3-32b 输出价格错误: %v", recordMap["huawei-maas-qwen3-32b"].OutputPrice)
}
if recordMap["huawei-maas-glm-5"].InputPrice != 0.004 || recordMap["huawei-maas-glm-5"].OutputPrice != 0.018 {
t.Fatalf("glm-5 阶梯基线价格错误: %v / %v", recordMap["huawei-maas-glm-5"].InputPrice, recordMap["huawei-maas-glm-5"].OutputPrice)
}
}
func TestRunHuaweiMaaSPricingImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runHuaweiMaaSPricingImport(huaweiMaaSPricingImportConfig{
URL: defaultHuaweiMaaSPricingURL,
Fixture: filepath.Join("testdata", "huawei_maas_pricing_sample.json"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runHuaweiMaaSPricingImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=huawei-maas-pricing-import",
"models=3",
"operator=Huawei Cloud MaaS",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}