mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-15 01:32:56 +02:00
- Clients now subscribe to peer status changes. - The server manages and maintains these subscriptions. - Replaced raw string peer IDs with a custom peer ID type for better type safety and clarity.
50 lines
766 B
Go
50 lines
766 B
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/netbirdio/netbird/relay/messages"
|
|
)
|
|
|
|
type MocPeer struct {
|
|
id messages.PeerID
|
|
}
|
|
|
|
func (m *MocPeer) Close() {
|
|
|
|
}
|
|
|
|
func (m *MocPeer) ID() messages.PeerID {
|
|
return m.id
|
|
}
|
|
|
|
func TestStore_DeletePeer(t *testing.T) {
|
|
s := NewStore()
|
|
|
|
pID := messages.HashID("peer_one")
|
|
p := &MocPeer{id: pID}
|
|
s.AddPeer(p)
|
|
s.DeletePeer(p)
|
|
if _, ok := s.Peer(pID); ok {
|
|
t.Errorf("peer was not deleted")
|
|
}
|
|
}
|
|
|
|
func TestStore_DeleteDeprecatedPeer(t *testing.T) {
|
|
s := NewStore()
|
|
|
|
pID1 := messages.HashID("peer_one")
|
|
pID2 := messages.HashID("peer_one")
|
|
|
|
p1 := &MocPeer{id: pID1}
|
|
p2 := &MocPeer{id: pID2}
|
|
|
|
s.AddPeer(p1)
|
|
s.AddPeer(p2)
|
|
s.DeletePeer(p1)
|
|
|
|
if _, ok := s.Peer(pID2); !ok {
|
|
t.Errorf("second peer was deleted")
|
|
}
|
|
}
|