2024-09-08 12:06:14 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-09-16 16:11:10 +02:00
|
|
|
"net"
|
2024-09-08 12:06:14 +02:00
|
|
|
"testing"
|
2024-09-16 16:11:10 +02:00
|
|
|
"time"
|
2024-09-08 12:06:14 +02:00
|
|
|
|
|
|
|
"go.opentelemetry.io/otel"
|
|
|
|
|
|
|
|
"github.com/netbirdio/netbird/relay/metrics"
|
|
|
|
)
|
|
|
|
|
2024-09-16 16:11:10 +02:00
|
|
|
type mockConn struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) Read(b []byte) (n int, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) Write(b []byte) (n int, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) LocalAddr() net.Addr {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) RemoteAddr() net.Addr {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) SetDeadline(t time.Time) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) SetReadDeadline(t time.Time) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockConn) SetWriteDeadline(t time.Time) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-09-08 12:06:14 +02:00
|
|
|
func TestStore_DeletePeer(t *testing.T) {
|
|
|
|
s := NewStore()
|
|
|
|
|
|
|
|
m, _ := metrics.NewMetrics(context.Background(), otel.Meter(""))
|
|
|
|
|
|
|
|
p := NewPeer(m, []byte("peer_one"), nil, nil)
|
|
|
|
s.AddPeer(p)
|
|
|
|
s.DeletePeer(p)
|
|
|
|
if _, ok := s.Peer(p.String()); ok {
|
|
|
|
t.Errorf("peer was not deleted")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_DeleteDeprecatedPeer(t *testing.T) {
|
|
|
|
s := NewStore()
|
|
|
|
|
|
|
|
m, _ := metrics.NewMetrics(context.Background(), otel.Meter(""))
|
|
|
|
|
2024-09-16 16:11:10 +02:00
|
|
|
conn := &mockConn{}
|
|
|
|
p1 := NewPeer(m, []byte("peer_id"), conn, nil)
|
|
|
|
p2 := NewPeer(m, []byte("peer_id"), conn, nil)
|
2024-09-08 12:06:14 +02:00
|
|
|
|
|
|
|
s.AddPeer(p1)
|
|
|
|
s.AddPeer(p2)
|
|
|
|
s.DeletePeer(p1)
|
|
|
|
|
|
|
|
if _, ok := s.Peer(p2.String()); !ok {
|
|
|
|
t.Errorf("second peer was deleted")
|
|
|
|
}
|
|
|
|
}
|