Files
iotlcm/internal/service/generator_test.go
T
MiFaZhan 4e2cd43a55 chore: 初始开源发布
iotlcm-onelink-mock:OneLink 挡板服务(本地测试替身)。

- Go module 迁移至 git.5iot.com/iotlcm-public/iotlcm-onelink-mock
- 修复同毫秒内多次生成卡导致 ICCID/IMSI 唯一约束冲突
- 补 Apache-2.0 LICENSE,README 重写并新增 docs/deploy.md
- 移除内部部署资产(CI 触发器 / 镜像推送脚本 / 指定环境部署文档)
- 测试凭据改为 demo_appid / demo_password,真实手机号与内网 IP 脱敏
- 统一 LF 行尾并加 .gitattributes
2026-10-22 15:08:27 +08:00

87 lines
3.5 KiB
Go

package service
import (
"reflect"
"testing"
"time"
)
func TestInboundExportHeadersMatchLatestTemplate(t *testing.T) {
expected := []string{
"ICCID*", "MSISDN*", "IMSI*", "IMEI", "通道编号*", "卡类型", "上游套餐编码", "供应商编码",
"上游激活时间", "是否贴片转插拔", "是否运营商达量断网", "协议到期时间", "是否有测试期",
"测试期天数", "测试期最晚过期日期", "是否有沉默期", "沉默期天数", "沉默期最晚过期日期",
}
if !reflect.DeepEqual(inboundExportHeaders, expected) {
t.Fatalf("export headers = %#v, want %#v", inboundExportHeaders, expected)
}
}
func TestGeneratedCardsUseTimestampIdentifiersAndFixedTraffic(t *testing.T) {
batchTime := time.Date(2026, 7, 10, 10, 0, 0, 123000000, time.UTC)
cards := GenerateSIMCards(batchTime, 3)
if len(cards) != 3 {
t.Fatalf("generated card count = %d, want 3", len(cards))
}
first := cards[0]
second := cards[1]
if first.ICCID == second.ICCID || first.MSISDN == second.MSISDN || first.IMSI == second.IMSI || first.IMEI == second.IMEI {
t.Fatalf("generated identifiers should differ within a batch: first=%#v second=%#v", first, second)
}
if len(first.ICCID) != 20 || first.ICCID[:6] != "898604" {
t.Fatalf("iccid = %q, want 20 digits with 898604 prefix", first.ICCID)
}
if len(first.MSISDN) != 11 || first.MSISDN[:3] != "141" {
t.Fatalf("msisdn = %q, want 11 digits with 141 prefix", first.MSISDN)
}
if len(first.IMSI) != 15 || first.IMSI[:5] != "46004" {
t.Fatalf("imsi = %q, want 15 digits with 46004 prefix", first.IMSI)
}
if len(first.IMEI) != 15 || first.IMEI[:2] != "86" {
t.Fatalf("imei = %q, want 15 digits with 86 prefix", first.IMEI)
}
if first.MonthUsageKB != 18432 || first.MonthlyBaseKB != 18432 || first.DailyBaseKB != 614.4 {
t.Fatalf("fixed traffic not applied: month=%v monthly=%v daily=%v", first.MonthUsageKB, first.MonthlyBaseKB, first.DailyBaseKB)
}
if first.PoolUsageBytes != 18874368 {
t.Fatalf("pool usage bytes = %v, want 18874368", first.PoolUsageBytes)
}
if first.GrowthPerMinuteKB != 0 {
t.Fatalf("growth per minute = %v, want 0", first.GrowthPerMinuteKB)
}
if len(first.APNs) != 1 || first.APNs[0].Name != "CMIOT" || first.APNs[0].Status != "1" || first.APNs[0].UsageBytes != 18874368 {
t.Fatalf("apn not fixed to CMIOT usage: %#v", first.APNs)
}
}
func TestGeneratedExportRowMatchesInboundTemplateDefaults(t *testing.T) {
batchTime := time.Date(2026, 7, 10, 10, 0, 0, 0, time.UTC)
card := GenerateSIMCards(batchTime, 1)[0]
row := inboundExportRow(card)
if row["chanKey"] != "channel_yd_mock" {
t.Fatalf("chanKey = %q", row["chanKey"])
}
if row["cardType"] != "1" || row["upPkgCode"] != "CMIOT-SD-500M-24M-D01" || row["suppliersCode"] != "SUP_CMCC" {
t.Fatalf("package defaults not applied: %#v", row)
}
if row["upstreamActivationTime"] != "2026-07-10 10:00:00" {
t.Fatalf("activation time = %q", row["upstreamActivationTime"])
}
if row["insertToPlugEnabled"] != "true" || row["carrierTrafficCutoffEnabled"] != "false" {
t.Fatalf("boolean defaults not applied: %#v", row)
}
if row["agreementExpiryDate"] != "2027-07-10" {
t.Fatalf("agreement expiry = %q", row["agreementExpiryDate"])
}
if row["hasTestPeriod"] != "true" || row["testPeriodDays"] != "30" || row["testPeriodLatestExpiryDate"] != "2026-08-09" {
t.Fatalf("test period defaults not applied: %#v", row)
}
if row["hasSilentPeriod"] != "false" || row["silentPeriodDays"] != "" || row["silentPeriodLatestExpiryDate"] != "" {
t.Fatalf("silent period defaults not applied: %#v", row)
}
}