feat: 设备编号从 00000001 顺序分配
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user