Files
aiops/backend/cloud/huawei_billing_test.go
T
Logan.Li 9b895efee3 fix: 完善多云同步验证与实例统计
- 修复华为云签名、账单字段与区域映射缓存
- 按真实云实例更新账号服务器数并补充并发测试
2026-07-29 06:35:54 +08:00

46 lines
1.3 KiB
Go

package cloud
import (
"testing"
)
func TestDecodeHuaweiBillPageRecords(t *testing.T) {
body := []byte(`{
"currency":"CNY",
"total_count":1,
"records":[{
"service_type_name":"弹性云服务器",
"region_name":"华南-广州",
"consume_amount":"12.34"
}]
}`)
page, err := decodeHuaweiBillPage(body)
if err != nil {
t.Fatalf("解析华为云账单失败: %v", err)
}
if page.TotalCount != 1 || page.Currency != "CNY" || len(page.Records) != 1 {
t.Fatalf("账单分页字段错误: %+v", page)
}
record := page.Records[0]
if record.ServiceTypeName != "弹性云服务器" || record.RegionName != "华南-广州" {
t.Fatalf("账单维度字段错误: %+v", record)
}
if cost := huaweiBillRecordCost(record); cost != 12.34 {
t.Fatalf("实际消费金额错误: %v", cost)
}
}
func TestDecodeHuaweiBillPageFeeRecordsCompatibility(t *testing.T) {
body := []byte(`{"total_count":1,"fee_records":[{"official_amount":20,"discount_amount":3}]}`)
page, err := decodeHuaweiBillPage(body)
if err != nil {
t.Fatalf("解析旧版华为云账单失败: %v", err)
}
if len(page.FeeRecords) != 1 {
t.Fatalf("旧版 fee_records 未解析: %+v", page)
}
if cost := huaweiBillRecordCost(page.FeeRecords[0]); cost != 17 {
t.Fatalf("官网价减优惠金额错误: %v", cost)
}
}