github.com/cmd-stream/base-go@v0.0.0-20230813145615-dd6ac24c16f5/testdata/mock/Listener.go (about) 1 package mock 2 3 import ( 4 "net" 5 "time" 6 7 "github.com/ymz-ncnk/mok" 8 ) 9 10 func NewListener() Listener { 11 return Listener{ 12 Mock: mok.New("Listener"), 13 } 14 } 15 16 type Listener struct { 17 *mok.Mock 18 } 19 20 func (m Listener) RegisterAddr( 21 fn func() (addr net.Addr)) Listener { 22 m.Register("Addr", fn) 23 return m 24 } 25 26 func (m Listener) RegisterSetDeadline( 27 fn func(deadline time.Time) (err error)) Listener { 28 m.Register("SetDeadline", fn) 29 return m 30 } 31 32 func (m Listener) RegisterNSetDeadline(n int, 33 fn func(deadline time.Time) (err error)) Listener { 34 m.RegisterN("SetDeadline", n, fn) 35 return m 36 } 37 38 func (m Listener) RegisterAccept( 39 fn func() (conn net.Conn, err error)) Listener { 40 m.Register("Accept", fn) 41 return m 42 } 43 44 func (m Listener) RegisterClose( 45 fn func() (err error)) Listener { 46 m.Register("Close", fn) 47 return m 48 } 49 50 func (m Listener) Addr() (addr net.Addr) { 51 vals, err := m.Call("Addr") 52 if err != nil { 53 panic(err) 54 } 55 addr, _ = vals[0].(net.Addr) 56 return 57 } 58 59 func (m Listener) SetDeadline(deadline time.Time) (err error) { 60 vals, err := m.Call("SetDeadline", deadline) 61 if err != nil { 62 panic(err) 63 } 64 err, _ = vals[0].(error) 65 return 66 } 67 68 func (m Listener) Accept() (conn net.Conn, err error) { 69 vals, err := m.Call("Accept") 70 if err != nil { 71 panic(err) 72 } 73 conn, _ = vals[0].(net.Conn) 74 err, _ = vals[1].(error) 75 return 76 } 77 78 func (m Listener) Close() (conn error) { 79 vals, err := m.Call("Close") 80 if err != nil { 81 panic(err) 82 } 83 conn, _ = vals[0].(error) 84 return 85 }