github.com/cmd-stream/base-go@v0.0.0-20230813145615-dd6ac24c16f5/testdata/mock/ClientReconnectDelegate.go (about) 1 package mock 2 3 import ( 4 "net" 5 "reflect" 6 "time" 7 8 "github.com/cmd-stream/base-go" 9 "github.com/ymz-ncnk/mok" 10 ) 11 12 func NewReconnectClientDelegate() ReconnectClientDelegate { 13 return ReconnectClientDelegate{ 14 Mock: mok.New("ReconnectClientDelegate"), 15 } 16 } 17 18 type ReconnectClientDelegate struct { 19 *mok.Mock 20 } 21 22 func (m ReconnectClientDelegate) RegisterReconnect( 23 fn func() (err error)) ReconnectClientDelegate { 24 m.Register("Reconnect", fn) 25 return m 26 } 27 28 func (m ReconnectClientDelegate) RegisterLocalAddr( 29 fn func() (addr net.Addr)) ReconnectClientDelegate { 30 m.Register("LocalAddr", fn) 31 return m 32 } 33 34 func (m ReconnectClientDelegate) RegisterRemoteAddr( 35 fn func() (addr net.Addr)) ReconnectClientDelegate { 36 m.Register("RemoteAddr", fn) 37 return m 38 } 39 40 func (m ReconnectClientDelegate) RegisterNSetSendDeadline(n int, 41 fn func(deadline time.Time) (err error)) ReconnectClientDelegate { 42 m.RegisterN("SetSendDeadline", n, fn) 43 return m 44 } 45 46 func (m ReconnectClientDelegate) RegisterSetSendDeadline( 47 fn func(deadline time.Time) (err error)) ReconnectClientDelegate { 48 m.Register("SetSendDeadline", fn) 49 return m 50 } 51 52 func (m ReconnectClientDelegate) RegisterNSend(n int, 53 fn func(seq base.Seq, cmd base.Cmd[any]) (err error)) ReconnectClientDelegate { 54 m.RegisterN("Send", n, fn) 55 return m 56 } 57 58 func (m ReconnectClientDelegate) RegisterSend( 59 fn func(seq base.Seq, cmd base.Cmd[any]) (err error)) ReconnectClientDelegate { 60 m.Register("Send", fn) 61 return m 62 } 63 64 func (m ReconnectClientDelegate) RegisterNFlush(n int, 65 fn func() (err error)) ReconnectClientDelegate { 66 m.RegisterN("Flush", n, fn) 67 return m 68 } 69 70 func (m ReconnectClientDelegate) RegisterFlush( 71 fn func() (err error)) ReconnectClientDelegate { 72 m.Register("Flush", fn) 73 return m 74 } 75 76 func (m ReconnectClientDelegate) RegisterNSetReceiveDeadline(n int, 77 fn func(deadline time.Time) (err error)) ReconnectClientDelegate { 78 m.RegisterN("SetReceiveDeadline", n, fn) 79 return m 80 } 81 82 func (m ReconnectClientDelegate) RegisterSetReceiveDeadline( 83 fn func(deadline time.Time) (err error)) ReconnectClientDelegate { 84 m.Register("SetReceiveDeadline", fn) 85 return m 86 } 87 88 func (m ReconnectClientDelegate) RegisterReceive( 89 fn func() (seq base.Seq, result base.Result, err error)) ReconnectClientDelegate { 90 m.Register("Receive", fn) 91 return m 92 } 93 94 func (m ReconnectClientDelegate) RegisterClose( 95 fn func() (err error)) ReconnectClientDelegate { 96 m.Register("Close", fn) 97 return m 98 } 99 100 func (m ReconnectClientDelegate) Reconnect() (err error) { 101 vals, err := m.Call("Reconnect") 102 if err != nil { 103 panic(err) 104 } 105 err, _ = vals[0].(error) 106 return 107 } 108 109 func (m ReconnectClientDelegate) LocalAddr() (addr net.Addr) { 110 vals, err := m.Call("LocalAddr") 111 if err != nil { 112 panic(err) 113 } 114 addr, _ = vals[0].(net.Addr) 115 return 116 } 117 118 func (m ReconnectClientDelegate) RemoteAddr() (addr net.Addr) { 119 vals, err := m.Call("RemoteAddr") 120 if err != nil { 121 panic(err) 122 } 123 addr, _ = vals[0].(net.Addr) 124 return 125 } 126 127 func (m ReconnectClientDelegate) SetSendDeadline(deadline time.Time) (err error) { 128 vals, err := m.Call("SetSendDeadline", deadline) 129 if err != nil { 130 panic(err) 131 } 132 err, _ = vals[0].(error) 133 return 134 } 135 136 func (m ReconnectClientDelegate) Send(seq base.Seq, cmd base.Cmd[any]) (err error) { 137 var cmdVal reflect.Value 138 if cmd == nil { 139 cmdVal = reflect.Zero(reflect.TypeOf((*base.Cmd[any])(nil)).Elem()) 140 } else { 141 cmdVal = reflect.ValueOf(cmd) 142 } 143 vals, err := m.Call("Send", seq, cmdVal) 144 if err != nil { 145 panic(err) 146 } 147 err, _ = vals[0].(error) 148 return 149 } 150 151 func (m ReconnectClientDelegate) Flush() (err error) { 152 vals, err := m.Call("Flush") 153 if err != nil { 154 panic(err) 155 } 156 err, _ = vals[0].(error) 157 return 158 } 159 160 func (m ReconnectClientDelegate) SetReceiveDeadline(deadline time.Time) (err error) { 161 vals, err := m.Call("SetReceiveDeadline", deadline) 162 if err != nil { 163 panic(err) 164 } 165 err, _ = vals[0].(error) 166 return 167 } 168 169 func (m ReconnectClientDelegate) Receive() (seq base.Seq, result base.Result, err error) { 170 vals, err := m.Call("Receive") 171 if err != nil { 172 panic(err) 173 } 174 seq, _ = vals[0].(base.Seq) 175 result, _ = vals[1].(base.Result) 176 err, _ = vals[2].(error) 177 return 178 } 179 180 func (m ReconnectClientDelegate) Close() (err error) { 181 vals, err := m.Call("Close") 182 if err != nil { 183 panic(err) 184 } 185 err, _ = vals[0].(error) 186 return 187 } 188 189 // func NewReconnectClientDelegate() ReconnectClientDelegate { 190 // return ReconnectClientDelegate{ 191 // ClientDelegate{ 192 // Mock: mok.New("ReconnectClientDelegate"), 193 // }, 194 // } 195 // } 196 197 // type ReconnectClientDelegate struct { 198 // ClientDelegate 199 // } 200 201 // func (m ReconnectClientDelegate) RegisterReconnect( 202 // fn func(seq base.Seq, cmd base.Cmd[any]) (err error)) ReconnectClientDelegate { 203 // m.Register("Reconnect", fn) 204 // return m 205 // } 206 207 // func (m ReconnectClientDelegate) Reconnect() (err error) { 208 // vals, err := m.Call("Reconnect") 209 // if err != nil { 210 // panic(err) 211 // } 212 // err, _ = vals[0].(error) 213 // return 214 // }