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
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestOneLinkDataDiagnosisUsesConfiguredAPNAndPCC(t *testing.T) {
|
||||
service, err := NewService(t.TempDir() + "/mock.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := service.store.Snapshot()
|
||||
st.Cards = GenerateSIMCards(time.Now(), 1)
|
||||
card := &st.Cards[0]
|
||||
card.APNs[0].DiagnosisStatus = "4"
|
||||
card.APNs[0].ServiceUsageState = "96"
|
||||
card.APNs[0].OverUseDetails = "16|17"
|
||||
card.APNs[0].PCCs = []PCC{{ServiceCode: "2323232", Name: "APN 缺省流量", PolicyStatus: "4", ServiceUsageState: "1", ModifyTime: "20220812154700"}}
|
||||
if err := service.store.SaveMutation(func(next *Store) error { *next = st; return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
st = service.store.Snapshot()
|
||||
token := "diagnosis-test-token"
|
||||
if err := service.store.SaveMutation(func(next *Store) error {
|
||||
next.Tokens[st.AppIDs[0].AppID] = Token{Value: token, ExpiresAt: nowPlusHour()}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodGet, "/v5/ec/query/sim-data-diagnosis?token="+token+"&msisdn="+st.Cards[0].MSISDN, nil)
|
||||
res := httptest.NewRecorder()
|
||||
service.Router().ServeHTTP(res, req)
|
||||
if res.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", res.Code, res.Body.String())
|
||||
}
|
||||
var body Response
|
||||
if err := json.Unmarshal(res.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body.Status != "0" {
|
||||
t.Fatalf("response=%s", res.Body.String())
|
||||
}
|
||||
encoded, _ := json.Marshal(body.Result)
|
||||
text := string(encoded)
|
||||
for _, want := range []string{"\"apnStatus\":\"4\"", "\"apnServiceUsageState\":\"96\"", "\"overUseDetails\":\"16|17\"", "\"pccServiceCode\":\"2323232\"", "\"pccPolicyStatus\":\"4\""} {
|
||||
if !contains(text, want) {
|
||||
t.Fatalf("missing %s in %s", want, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCardBindStatusRequiresMSISDNAndTestType(t *testing.T) {
|
||||
service, err := NewService(t.TempDir() + "/mock.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := service.store.Snapshot()
|
||||
st.Cards = GenerateSIMCards(time.Now(), 1)
|
||||
token := "bind-test-token"
|
||||
if err := service.store.SaveMutation(func(next *Store) error {
|
||||
next.Tokens[st.AppIDs[0].AppID] = Token{Value: token, ExpiresAt: nowPlusHour()}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, query := range []string{"iccid=" + st.Cards[0].ICCID + "&testType=0", "msisdn=" + st.Cards[0].MSISDN} {
|
||||
req := httptest.NewRequest(http.MethodGet, "/v5/ec/query/card-bind-status?token="+token+"&"+query, nil)
|
||||
res := httptest.NewRecorder()
|
||||
service.Router().ServeHTTP(res, req)
|
||||
var body Response
|
||||
if err := json.Unmarshal(res.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body.Status == "0" {
|
||||
t.Fatalf("expected validation failure for %s", query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func nowPlusHour() (value time.Time) { return time.Now().Add(time.Hour) }
|
||||
func contains(value, want string) bool { return strings.Contains(value, want) }
|
||||
Reference in New Issue
Block a user