feat: 设备编号从 00000001 顺序分配
This commit is contained in:
@@ -30,18 +30,18 @@ func newFakeNix() *fakeNix {
|
||||
return &fakeNix{online: map[string]bool{}, passwords: map[string]string{}}
|
||||
}
|
||||
|
||||
func (f *fakeNix) CreateEndpoint(context.Context, string) (string, string, error) {
|
||||
func (f *fakeNix) CreateEndpoint(_ context.Context, id, name string) (string, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.next++
|
||||
id := "e_dev" + string(rune('0'+f.next))
|
||||
if f.next >= 10 {
|
||||
id = "e_devx"
|
||||
if id == "" {
|
||||
f.next++
|
||||
id = "e_dev"
|
||||
}
|
||||
pw := "DevicePassw0rd" + string(rune('0'+f.next))
|
||||
f.online[id] = f.next == 1
|
||||
_ = name
|
||||
pw := "DevicePassw0rd"
|
||||
f.online[id] = true
|
||||
f.passwords[id] = pw
|
||||
return id, pw, nil
|
||||
return pw, nil
|
||||
}
|
||||
|
||||
func (f *fakeNix) Lookup(_ context.Context, id string) (bool, bool, error) {
|
||||
@@ -262,7 +262,7 @@ func TestGroupsDevicesAndLogs(t *testing.T) {
|
||||
deviceID := created["id"]
|
||||
endpointID, _ := created["endpoint_id"].(string)
|
||||
password, _ := created["login_password"].(string)
|
||||
if endpointID == "" || password == "" {
|
||||
if endpointID != "00000001" || password == "" {
|
||||
t.Fatalf("missing one-time secret %#v", created)
|
||||
}
|
||||
if created["presence"] != "online" {
|
||||
@@ -273,6 +273,9 @@ func TestGroupsDevicesAndLogs(t *testing.T) {
|
||||
t.Fatalf("second device %d %#v", status, body)
|
||||
}
|
||||
secondID := dataOf(t, body)["endpoint_id"].(string)
|
||||
if secondID != "00000002" {
|
||||
t.Fatalf("second endpoint %s", secondID)
|
||||
}
|
||||
|
||||
status, body = alice.call(t, http.MethodGet, "/api/devices", nil, false)
|
||||
if status != http.StatusOK {
|
||||
|
||||
Reference in New Issue
Block a user