-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_listener_test.go
81 lines (61 loc) · 1.52 KB
/
fake_listener_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package watermillnet_test
import (
"net"
"time"
watermillnet "github.com/andyollylarkin/watermill-net"
)
type listenerStub struct {
Conn watermillnet.Connection
}
func NewListenerStub(conn net.Conn) *listenerStub {
s := new(listenerStub)
s.Conn = NewConnWrapper(conn)
return s
}
func NewListenerStubWithFakeConn(conn watermillnet.Connection) *listenerStub {
s := new(listenerStub)
s.Conn = conn
return s
}
func (ls *listenerStub) Accept() (watermillnet.Connection, error) {
return ls.Conn, nil
}
func (ls *listenerStub) Close() error { return ls.Conn.Close() }
func (ls *listenerStub) Addr() net.Addr { return ls.Conn.LocalAddr() }
type connWrapper struct {
C net.Conn
Closed bool
}
func NewConnWrapper(conn net.Conn) *connWrapper {
cw := new(connWrapper)
cw.C = conn
return cw
}
func (pc *connWrapper) Read(b []byte) (n int, err error) {
return pc.C.Read(b)
}
func (pc *connWrapper) Write(b []byte) (n int, err error) {
return pc.C.Write(b)
}
func (pc *connWrapper) Close() error {
pc.Closed = true
return pc.C.Close()
}
func (pc *connWrapper) LocalAddr() net.Addr {
return pc.C.LocalAddr()
}
func (pc *connWrapper) RemoteAddr() net.Addr {
return pc.C.RemoteAddr()
}
func (pc *connWrapper) SetDeadline(t time.Time) error {
return pc.C.SetDeadline(t)
}
func (pc *connWrapper) SetReadDeadline(t time.Time) error {
return pc.C.SetReadDeadline(t)
}
func (pc *connWrapper) SetWriteDeadline(t time.Time) error {
return pc.C.SetWriteDeadline(t)
}
func (pc *connWrapper) Connect(addr net.Addr) error {
return nil
}