feat: 设备编号从 00000001 顺序分配

This commit is contained in:
Nixevol
2026-10-12 08:54:17 +08:00
parent 775599174b
commit c334dbc040
8 changed files with 119 additions and 29 deletions
+32
View File
@@ -116,3 +116,35 @@ func TestLastEnabledAdmin(t *testing.T) {
t.Fatalf("last admin: %v", err)
}
}
func TestAllocateEndpointID(t *testing.T) {
st := openTest(t)
ctx := context.Background()
first, err := st.AllocateEndpointID(ctx)
if err != nil {
t.Fatal(err)
}
if first != "00000001" {
t.Fatalf("first %s", first)
}
second, err := st.AllocateEndpointID(ctx)
if err != nil {
t.Fatal(err)
}
if second != "00000002" {
t.Fatalf("second %s", second)
}
if _, err := st.db.ExecContext(ctx, `UPDATE endpoint_seq SET next_no = ? WHERE id = 1`, maxEndpointNo); err != nil {
t.Fatal(err)
}
last, err := st.AllocateEndpointID(ctx)
if err != nil {
t.Fatal(err)
}
if last != "99999999" {
t.Fatalf("last %s", last)
}
if _, err := st.AllocateEndpointID(ctx); err != ErrEndpointExhausted {
t.Fatalf("exhausted: %v", err)
}
}