github.com/cmd-stream/base-go@v0.0.0-20230813145615-dd6ac24c16f5/testdata/mock/Conn.go (about) 1 package mock 2 3 import ( 4 "net" 5 "time" 6 7 "github.com/ymz-ncnk/mok" 8 ) 9 10 // NewConn creates a new Conn. 11 func NewConn() Conn { 12 return Conn{ 13 Mock: mok.New("Conn"), 14 } 15 } 16 17 type Conn struct { 18 *mok.Mock 19 } 20 21 func (m Conn) RegisterLocalAddr( 22 fn func() (addr net.Addr)) Conn { 23 m.Register("LocalAddr", fn) 24 return m 25 } 26 27 func (m Conn) RegisterNRead(n int, 28 fn func(b []byte) (n int, err error)) Conn { 29 m.RegisterN("Read", n, fn) 30 return m 31 } 32 33 func (m Conn) RegisterRead( 34 fn func(b []byte) (n int, err error)) Conn { 35 m.Register("Read", fn) 36 return m 37 } 38 39 func (m Conn) RegisterRemoteAddr( 40 fn func() (addr net.Addr)) Conn { 41 m.Register("RemoteAddr", fn) 42 return m 43 } 44 45 func (m Conn) RegisterSetDeadline( 46 fn func(deadline time.Time) (err error)) Conn { 47 m.Register("SetDeadline", fn) 48 return m 49 } 50 51 func (m Conn) RegisterNSetReadDeadline(n int, 52 fn func(deadline time.Time) (err error)) Conn { 53 m.RegisterN("SetReadDeadline", n, fn) 54 return m 55 } 56 57 func (m Conn) RegisterSetReadDeadline( 58 fn func(deadline time.Time) (err error)) Conn { 59 m.Register("SetReadDeadline", fn) 60 return m 61 } 62 63 func (m Conn) RegisterSetWriteDeadline( 64 fn func(deadline time.Time) (err error)) Conn { 65 m.Register("SetWriteDeadline", fn) 66 return m 67 } 68 69 func (m Conn) RegisterWrite( 70 fn func(b []byte) (n int, err error)) Conn { 71 m.Register("Write", fn) 72 return m 73 } 74 75 func (m Conn) RegisterClose( 76 fn func() (err error)) Conn { 77 m.Register("Close", fn) 78 return m 79 } 80 81 func (m Conn) LocalAddr() (addr net.Addr) { 82 vals, err := m.Call("LocalAddr") 83 if err != nil { 84 panic(err) 85 } 86 addr, _ = vals[0].(net.Addr) 87 return 88 } 89 90 func (m Conn) RemoteAddr() (addr net.Addr) { 91 vals, err := m.Call("RemoteAddr") 92 if err != nil { 93 panic(err) 94 } 95 addr, _ = vals[0].(net.Addr) 96 return 97 } 98 99 func (m Conn) SetDeadline(deadline time.Time) (err error) { 100 vals, err := m.Call("SetDeadline", deadline) 101 if err != nil { 102 panic(err) 103 } 104 err, _ = vals[0].(error) 105 return 106 } 107 108 func (m Conn) SetReadDeadline(deadline time.Time) (err error) { 109 vals, err := m.Call("SetReadDeadline", deadline) 110 if err != nil { 111 panic(err) 112 } 113 err, _ = vals[0].(error) 114 return 115 } 116 117 func (m Conn) SetWriteDeadline(deadline time.Time) (err error) { 118 vals, err := m.Call("SetWriteDeadline", deadline) 119 if err != nil { 120 panic(err) 121 } 122 err, _ = vals[0].(error) 123 return 124 } 125 126 func (m Conn) Write(b []byte) (n int, err error) { 127 vals, err := m.Call("Write", b) 128 if err != nil { 129 panic(err) 130 } 131 n = vals[0].(int) 132 err, _ = vals[1].(error) 133 return 134 } 135 136 func (m Conn) Read(b []byte) (n int, err error) { 137 vals, err := m.Call("Read", b) 138 if err != nil { 139 panic(err) 140 } 141 n = vals[0].(int) 142 err, _ = vals[1].(error) 143 return 144 } 145 146 func (m Conn) Close() (err error) { 147 vals, err := m.Call("Close") 148 if err != nil { 149 panic(err) 150 } 151 err, _ = vals[0].(error) 152 return 153 }