-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn_mock.go
40 lines (34 loc) · 942 Bytes
/
conn_mock.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
package noye
// MockConn is a type that implements noye.Conn
// which can have parts of it overridden by changing the functors
type MockConn struct {
DialFn func(string) error
CloseFn func()
WriteLineFn func(string)
ReadLineFn func() (string, error)
}
// NewMockConn returns a new MockConn with the fns set to no-ops
func NewMockConn() *MockConn {
return &MockConn{
DialFn: func(string) error { return nil },
CloseFn: func() {},
WriteLineFn: func(string) {},
ReadLineFn: func() (string, error) { return "", nil },
}
}
// Dial delegates to DialFn
func (m *MockConn) Dial(addr string) error {
return m.DialFn(addr)
}
// Close delegates to CloseFn
func (m *MockConn) Close() {
m.CloseFn()
}
// WriteLine delegates to WriteLineFn
func (m *MockConn) WriteLine(raw string) {
m.WriteLineFn(raw)
}
// ReadLine delegates to ReadLineFn
func (m *MockConn) ReadLine() (string, error) {
return m.ReadLineFn()
}