chore: 并入 iotlcm-onelink-mock 历史到 onelink-mock/(原提交 f398595)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
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: "14100000001", 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user