Files
go-libp2p/config/muxer_test.go
T
Steven Allen 41c6834850 refactor for transport changes
Also, make the libp2p constructor fully useful. There should now be no need to
manually construct a swarm/host.
2018-06-04 21:22:24 -07:00

55 lines
1.1 KiB
Go

package config
import (
"testing"
peer "github.com/libp2p/go-libp2p-peer"
mux "github.com/libp2p/go-stream-muxer"
yamux "github.com/whyrusleeping/go-smux-yamux"
)
func TestMuxerSimple(t *testing.T) {
// single
_, err := MuxerConstructor(func(_ peer.ID) mux.Transport { return nil })
if err != nil {
t.Fatal(err)
}
}
func TestMuxerByValue(t *testing.T) {
_, err := MuxerConstructor(yamux.DefaultTransport)
if err != nil {
t.Fatal(err)
}
}
func TestMuxerDuplicate(t *testing.T) {
_, err := MuxerConstructor(func(_ peer.ID, _ peer.ID) mux.Transport { return nil })
if err != nil {
t.Fatal(err)
}
}
func TestMuxerError(t *testing.T) {
_, err := MuxerConstructor(func() (mux.Transport, error) { return nil, nil })
if err != nil {
t.Fatal(err)
}
}
func TestMuxerBadTypes(t *testing.T) {
for i, f := range []interface{}{
func() error { return nil },
func() string { return "" },
func() {},
func(string) mux.Transport { return nil },
func(string) (mux.Transport, error) { return nil, nil },
nil,
"testing",
} {
if _, err := MuxerConstructor(f); err == nil {
t.Fatalf("constructor %d with type %T should have failed", i, f)
}
}
}