forked from libp2p/go-libp2p-swarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport_test.go
47 lines (37 loc) · 1.04 KB
/
transport_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package swarm_test
import (
"context"
"testing"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
peer "github.com/libp2p/go-libp2p-peer"
transport "github.com/libp2p/go-libp2p-transport"
ma "github.com/multiformats/go-multiaddr"
)
type dummyTransport struct {
protocols []int
proxy bool
}
func (dt *dummyTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (transport.Conn, error) {
panic("unimplemented")
}
func (dt *dummyTransport) CanDial(addr ma.Multiaddr) bool {
panic("unimplemented")
}
func (dt *dummyTransport) Listen(laddr ma.Multiaddr) (transport.Listener, error) {
panic("unimplemented")
}
func (dt *dummyTransport) Proxy() bool {
return dt.proxy
}
func (dt *dummyTransport) Protocols() []int {
return dt.protocols
}
func TestUselessTransport(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
swarm := swarmt.GenSwarm(t, ctx)
err := swarm.AddTransport(new(dummyTransport))
if err == nil {
t.Fatal("adding a transport that supports no protocols should have failed")
}
}