Files
iotlcm/internal/service/store_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

72 lines
1.9 KiB
Go

package service
import "testing"
func TestStoreManagerUsesSQLiteWithoutExternalDatabase(t *testing.T) {
manager, err := NewStoreManager(t.TempDir() + "/onelink_mock.db")
if err != nil {
t.Fatal(err)
}
got := manager.Snapshot()
if len(got.Cards) != 0 {
t.Fatalf("new sqlite store should not contain sample cards, got %#v", got.Cards)
}
if len(got.AppIDs) == 0 || got.AppIDs[0].AppID != "demo_appid" {
t.Fatalf("default app id not preserved: %#v", got.AppIDs)
}
}
func TestStoreManagerGenerateCardsAppendsWithoutDeletingOldCards(t *testing.T) {
manager, err := NewStoreManager(t.TempDir() + "/onelink_mock.db")
if err != nil {
t.Fatal(err)
}
first, err := manager.GenerateCards(2)
if err != nil {
t.Fatal(err)
}
if first.Generated != 2 {
t.Fatalf("first generated = %d, want 2", first.Generated)
}
second, err := manager.GenerateCards(1)
if err != nil {
t.Fatal(err)
}
if second.Generated != 1 || second.Total != 3 {
t.Fatalf("second result = %#v, want generated 1 total 3", second)
}
got := manager.Snapshot()
if len(got.Cards) != 3 {
t.Fatalf("generated cards should append, got %d cards: %#v", len(got.Cards), got.Cards)
}
}
func TestOrdersPersistAcrossStoreRestart(t *testing.T) {
dbPath := t.TempDir() + "/onelink_mock.db"
manager, err := NewStoreManager(dbPath)
if err != nil {
t.Fatal(err)
}
want := Order{
OrderNum: "ORD202607270001", MSISDN: "138****8000", ICCID: "8986000000000000001",
IMSI: "460000000000001", Type: "sim-apn-function", OperType: "1",
APNName: "CMIOT", Status: "completed", CreatedAt: "2026-07-27 16:00:00",
}
if err := manager.SaveMutation(func(st *Store) error {
st.Orders = append(st.Orders, want)
return nil
}); err != nil {
t.Fatal(err)
}
reopened, err := NewStoreManager(dbPath)
if err != nil {
t.Fatal(err)
}
got := reopened.Snapshot().Orders
if len(got) != 1 || got[0] != want {
t.Fatalf("orders after restart = %#v, want %#v", got, want)
}
}