You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
825 B
38 lines
825 B
2 years ago
|
package p2p
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
|
||
|
libp2p_network "github.com/libp2p/go-libp2p-core/network"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestConnectCallbacks(t *testing.T) {
|
||
|
cbs := ConnectCallbacks{}
|
||
|
fn := func(net libp2p_network.Network, conn libp2p_network.Conn) error {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
require.Equal(t, 0, len(cbs.GetAll()))
|
||
|
|
||
|
cbs.Add(fn)
|
||
|
|
||
|
require.Equal(t, 1, len(cbs.GetAll()))
|
||
|
require.Equal(t, reflect.ValueOf(fn).Pointer(), reflect.ValueOf(cbs.GetAll()[0]).Pointer())
|
||
|
}
|
||
|
|
||
|
func TestDisConnectCallbacks(t *testing.T) {
|
||
|
cbs := DisconnectCallbacks{}
|
||
|
fn := func(conn libp2p_network.Conn) error {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
require.Equal(t, 0, len(cbs.GetAll()))
|
||
|
|
||
|
cbs.Add(fn)
|
||
|
|
||
|
require.Equal(t, 1, len(cbs.GetAll()))
|
||
|
require.Equal(t, reflect.ValueOf(fn).Pointer(), reflect.ValueOf(cbs.GetAll()[0]).Pointer())
|
||
|
}
|