-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpeer_connector_test.go
54 lines (42 loc) · 1.05 KB
/
peer_connector_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
48
49
50
51
52
53
54
package meshboi
import (
"net"
"testing"
"inet.af/netaddr"
)
type testListenerDialer struct {
dialer net.Dialer
dialed chan (net.Addr)
}
func (t testListenerDialer) DialMesh(raddr net.Addr) (MeshConn, error) {
t.dialed <- raddr
c, _ := net.Pipe()
ip := netaddr.MustParseIP("192.168.1.1")
return &meshConn{
Conn: c,
remoteMeshAddr: ip,
}, nil
}
func (t testListenerDialer) AcceptMesh() (MeshConn, error) {
return nil, nil
}
func (t testListenerDialer) Dial(raddr net.Addr) (net.Conn, error) {
fakeConn, _ := net.Pipe()
return fakeConn, nil
}
func TestPeerConnector(t *testing.T) {
td := testListenerDialer{dialed: make(chan net.Addr)}
store := NewPeerConnStore()
client, _ := net.Pipe()
pc := NewPeerConnector(td, store, client)
nm := NetworkMap{
Addresses: []netaddr.IPPort{netaddr.MustParseIPPort("192.168.33.1:3000"),
netaddr.MustParseIPPort("192.168.33.2:4000")},
YourIndex: 0,
}
go pc.OnNetworkMapUpdate(nm)
dialed := <-td.dialed
if dialed.String() != "192.168.33.2:4000" {
t.Fatalf("Dialed wrong address")
}
}