Files
iotlcm/server/internal/logic/iot/t_sim_diagnose_test.go
T
2026-10-29 14:36:49 +08:00

75 lines
2.9 KiB
Go

package iot
import (
"testing"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
)
func TestDiagnoseDataServiceStatusUsesTargetApn(t *testing.T) {
tests := []struct {
name string
items []model.SimApnInfoItem
want string
}{
{name: "enabled", items: []model.SimApnInfoItem{{ApnName: "OTHER", Status: "0"}, {ApnName: "CMIOT", Status: "1"}}, want: "1"},
{name: "disabled", items: []model.SimApnInfoItem{{ApnName: "cmiot", Status: "0"}}, want: "0"},
{name: "missing target", items: []model.SimApnInfoItem{{ApnName: "OTHER", Status: "1"}}},
{name: "invalid status", items: []model.SimApnInfoItem{{ApnName: "CMIOT", Status: "unknown"}}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := diagnoseDataServiceStatus(test.items)
if test.want == "" {
if got != nil {
t.Fatalf("status = %q, want no data", *got)
}
return
}
if got == nil || *got != test.want {
t.Fatalf("status = %v, want %q", got, test.want)
}
})
}
}
func TestDiagnoseAPNStatusRequiresAgreement(t *testing.T) {
tests := []struct {
name string
items []model.SimApnInfoItem
want string
}{
{name: "all enabled", items: []model.SimApnInfoItem{{ApnName: "ctnet", Status: "1"}, {ApnName: "ctiot", Status: "1"}}, want: "1"},
{name: "all stopped", items: []model.SimApnInfoItem{{ApnName: "ctnet", Status: "0"}, {ApnName: "ctiot", Status: "0"}}, want: "0"},
{name: "mixed", items: []model.SimApnInfoItem{{ApnName: "ctnet", Status: "1"}, {ApnName: "ctiot", Status: "0"}}},
{name: "mixed reversed", items: []model.SimApnInfoItem{{ApnName: "ctiot", Status: "0"}, {ApnName: "ctnet", Status: "1"}}},
{name: "missing status", items: []model.SimApnInfoItem{{ApnName: "ctnet", Status: "1"}, {ApnName: "ctiot"}}},
{name: "unknown status", items: []model.SimApnInfoItem{{ApnName: "ctnet", Status: "1"}, {ApnName: "ctiot", Status: "-1"}}},
{name: "missing name", items: []model.SimApnInfoItem{{Status: "1"}}},
{name: "no mobile preference for telecom", items: []model.SimApnInfoItem{{ApnName: "CMIOT", Status: "1"}, {ApnName: "ctnet", Status: "0"}}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := diagnoseDataServiceStatusForChannel(test.items, "sim_dx_v1", "channel_dx")
if test.want == "" {
if got != nil {
t.Fatalf("status = %q, want no data", *got)
}
} else if got == nil || *got != test.want {
t.Fatalf("status = %v, want %q", got, test.want)
}
})
}
}
func TestDiagnoseDataServiceStatusForCarrier(t *testing.T) {
telecom := []model.SimApnInfoItem{{ApnName: "CTNET", Status: "1"}}
if got := diagnoseDataServiceStatusForChannel(telecom, "sim_dx_v1", "channel_dx"); got == nil || *got != "1" {
t.Fatalf("telecom status = %v, want enabled", got)
}
mobile := []model.SimApnInfoItem{{ApnName: "CTNET", Status: "1"}}
if got := diagnoseDataServiceStatusForChannel(mobile, "sim_yd_v5", "channel_yd"); got != nil {
t.Fatalf("mobile status = %v, want no CMIOT data", *got)
}
}