mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-07 08:44:07 +01:00
test: add signal peer test
This commit is contained in:
parent
9b327ea6ba
commit
33a98c7a2c
@ -47,8 +47,8 @@ func (reg *Registry) Register(peer *Peer) {
|
||||
reg.Peers[peer.Id] = peer
|
||||
}
|
||||
|
||||
// DeregisterHub deregister Peer from the Registry (usually once it disconnects)
|
||||
func (reg *Registry) DeregisterHub(peer *Peer) {
|
||||
// Deregister deregister Peer from the Registry (usually once it disconnects)
|
||||
func (reg *Registry) Deregister(peer *Peer) {
|
||||
if _, ok := reg.Peers[peer.Id]; ok {
|
||||
delete(reg.Peers, peer.Id)
|
||||
log.Printf("deregistered peer [%s]", peer.Id)
|
||||
|
48
signal/peer/peer_test.go
Normal file
48
signal/peer/peer_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package peer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRegistry_Register(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
peer1 := NewPeer("test_peer_1", nil)
|
||||
peer2 := NewPeer("test_peer_2", nil)
|
||||
r.Register(peer1)
|
||||
r.Register(peer2)
|
||||
|
||||
if len(r.Peers) != 2 {
|
||||
t.Errorf("expected 2 registered peers")
|
||||
}
|
||||
|
||||
if _, ok := r.Peers["test_peer_1"]; !ok {
|
||||
t.Errorf("expected test_peer_1 not found in the registry")
|
||||
}
|
||||
|
||||
if _, ok := r.Peers["test_peer_2"]; !ok {
|
||||
t.Errorf("expected test_peer_2 not found in the registry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistry_Deregister(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
peer1 := NewPeer("test_peer_1", nil)
|
||||
peer2 := NewPeer("test_peer_2", nil)
|
||||
r.Register(peer1)
|
||||
r.Register(peer2)
|
||||
|
||||
r.Deregister(peer1)
|
||||
|
||||
if len(r.Peers) != 1 {
|
||||
t.Errorf("expected 1 registered peers after deregistring")
|
||||
}
|
||||
|
||||
if _, ok := r.Peers["test_peer_1"]; ok {
|
||||
t.Errorf("expected test_peer_1 to absent in the registry after deregistering")
|
||||
}
|
||||
|
||||
if _, ok := r.Peers["test_peer_2"]; !ok {
|
||||
t.Errorf("expected test_peer_2 not found in the registry")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user