[client] Refactor Android PeerInfo to use proper ConnStatus enum type (#5644)

* Simplify Android ConnStatus API with integer constants

Replace dual field PeerInfo design with unified integer based
ConnStatus field and exported gomobile friendly constants.

Changes:
> PeerInfo.ConnStatus: changed from string to int
> Export three constants: ConnStatusIdle, ConnStatusConnecting,ConnStatusConnected (mapped to peer.ConnStatus enum values)
> Updated PeersList() to convert peer enum directly to int

Benefits:
> Simpler API surface with single ConnStatus field
> Better gomobile compatibility for cross-platform usage
> Type-safe integer constants across language boundaries

* test: add All group to setupTestAccount fixture

The setupTestAccount() test helper was missing the required "All" group,
causing "failed to get group all: no group ALL found" errors during
test execution. Add the All group with all test peers to match the
expected account structure.

Fixes the failing account and types package tests when GetGroupAll()
is called in test scenarios.
This commit is contained in:
Akshay Ubale
2026-03-30 17:55:01 +02:00
committed by GitHub
parent 04dcaadabf
commit 7bbe71c3ac
3 changed files with 17 additions and 2 deletions

View File

@@ -205,7 +205,7 @@ func (c *Client) PeersList() *PeerInfoArray {
pi := PeerInfo{ pi := PeerInfo{
p.IP, p.IP,
p.FQDN, p.FQDN,
p.ConnStatus.String(), int(p.ConnStatus),
PeerRoutes{routes: maps.Keys(p.GetRoutes())}, PeerRoutes{routes: maps.Keys(p.GetRoutes())},
} }
peerInfos[n] = pi peerInfos[n] = pi

View File

@@ -2,11 +2,20 @@
package android package android
import "github.com/netbirdio/netbird/client/internal/peer"
// Connection status constants exported via gomobile.
const (
ConnStatusIdle = int(peer.StatusIdle)
ConnStatusConnecting = int(peer.StatusConnecting)
ConnStatusConnected = int(peer.StatusConnected)
)
// PeerInfo describe information about the peers. It designed for the UI usage // PeerInfo describe information about the peers. It designed for the UI usage
type PeerInfo struct { type PeerInfo struct {
IP string IP string
FQDN string FQDN string
ConnStatus string // Todo replace to enum ConnStatus int
Routes PeerRoutes Routes PeerRoutes
} }

View File

@@ -84,6 +84,12 @@ func setupTestAccount() *Account {
}, },
}, },
Groups: map[string]*Group{ Groups: map[string]*Group{
"groupAll": {
ID: "groupAll",
Name: "All",
Peers: []string{"peer1", "peer2", "peer3", "peer11", "peer12", "peer21", "peer31", "peer32", "peer41", "peer51", "peer61"},
Issued: GroupIssuedAPI,
},
"group1": { "group1": {
ID: "group1", ID: "group1",
Peers: []string{"peer11", "peer12"}, Peers: []string{"peer11", "peer12"},