github.com/cmd-stream/base-go@v0.0.0-20230813145615-dd6ac24c16f5/testdata/mock/ClientDelegate.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 NewClientDelegate() ClientDelegate {
    13  	return ClientDelegate{
    14  		Mock: mok.New("ClientDelegate"),
    15  	}
    16  }
    17  
    18  type ClientDelegate struct {
    19  	*mok.Mock
    20  }
    21  
    22  func (m ClientDelegate) RegisterLocalAddr(
    23  	fn func() (addr net.Addr)) ClientDelegate {
    24  	m.Register("LocalAddr", fn)
    25  	return m
    26  }
    27  
    28  func (m ClientDelegate) RegisterRemoteAddr(
    29  	fn func() (addr net.Addr)) ClientDelegate {
    30  	m.Register("RemoteAddr", fn)
    31  	return m
    32  }
    33  
    34  func (m ClientDelegate) RegisterNSetSendDeadline(n int,
    35  	fn func(deadline time.Time) (err error)) ClientDelegate {
    36  	m.RegisterN("SetSendDeadline", n, fn)
    37  	return m
    38  }
    39  
    40  func (m ClientDelegate) RegisterSetSendDeadline(
    41  	fn func(deadline time.Time) (err error)) ClientDelegate {
    42  	m.Register("SetSendDeadline", fn)
    43  	return m
    44  }
    45  
    46  func (m ClientDelegate) RegisterNSend(n int,
    47  	fn func(seq base.Seq, cmd base.Cmd[any]) (err error)) ClientDelegate {
    48  	m.RegisterN("Send", n, fn)
    49  	return m
    50  }
    51  
    52  func (m ClientDelegate) RegisterSend(
    53  	fn func(seq base.Seq, cmd base.Cmd[any]) (err error)) ClientDelegate {
    54  	m.Register("Send", fn)
    55  	return m
    56  }
    57  
    58  func (m ClientDelegate) RegisterNFlush(n int,
    59  	fn func() (err error)) ClientDelegate {
    60  	m.RegisterN("Flush", n, fn)
    61  	return m
    62  }
    63  
    64  func (m ClientDelegate) RegisterFlush(
    65  	fn func() (err error)) ClientDelegate {
    66  	m.Register("Flush", fn)
    67  	return m
    68  }
    69  
    70  func (m ClientDelegate) RegisterNSetReceiveDeadline(n int,
    71  	fn func(deadline time.Time) (err error)) ClientDelegate {
    72  	m.RegisterN("SetReceiveDeadline", n, fn)
    73  	return m
    74  }
    75  
    76  func (m ClientDelegate) RegisterSetReceiveDeadline(
    77  	fn func(deadline time.Time) (err error)) ClientDelegate {
    78  	m.Register("SetReceiveDeadline", fn)
    79  	return m
    80  }
    81  
    82  func (m ClientDelegate) RegisterReceive(
    83  	fn func() (seq base.Seq, result base.Result, err error)) ClientDelegate {
    84  	m.Register("Receive", fn)
    85  	return m
    86  }
    87  
    88  func (m ClientDelegate) RegisterClose(
    89  	fn func() (err error)) ClientDelegate {
    90  	m.Register("Close", fn)
    91  	return m
    92  }
    93  
    94  func (m ClientDelegate) LocalAddr() (addr net.Addr) {
    95  	vals, err := m.Call("LocalAddr")
    96  	if err != nil {
    97  		panic(err)
    98  	}
    99  	addr, _ = vals[0].(net.Addr)
   100  	return
   101  }
   102  
   103  func (m ClientDelegate) RemoteAddr() (addr net.Addr) {
   104  	vals, err := m.Call("RemoteAddr")
   105  	if err != nil {
   106  		panic(err)
   107  	}
   108  	addr, _ = vals[0].(net.Addr)
   109  	return
   110  }
   111  
   112  func (m ClientDelegate) SetSendDeadline(deadline time.Time) (err error) {
   113  	vals, err := m.Call("SetSendDeadline", deadline)
   114  	if err != nil {
   115  		panic(err)
   116  	}
   117  	err, _ = vals[0].(error)
   118  	return
   119  }
   120  
   121  func (m ClientDelegate) Send(seq base.Seq, cmd base.Cmd[any]) (err error) {
   122  	var cmdVal reflect.Value
   123  	if cmd == nil {
   124  		cmdVal = reflect.Zero(reflect.TypeOf((*base.Cmd[any])(nil)).Elem())
   125  	} else {
   126  		cmdVal = reflect.ValueOf(cmd)
   127  	}
   128  	vals, err := m.Call("Send", seq, cmdVal)
   129  	if err != nil {
   130  		panic(err)
   131  	}
   132  	err, _ = vals[0].(error)
   133  	return
   134  }
   135  
   136  func (m ClientDelegate) Flush() (err error) {
   137  	vals, err := m.Call("Flush")
   138  	if err != nil {
   139  		panic(err)
   140  	}
   141  	err, _ = vals[0].(error)
   142  	return
   143  }
   144  
   145  func (m ClientDelegate) SetReceiveDeadline(deadline time.Time) (err error) {
   146  	vals, err := m.Call("SetReceiveDeadline", deadline)
   147  	if err != nil {
   148  		panic(err)
   149  	}
   150  	err, _ = vals[0].(error)
   151  	return
   152  }
   153  
   154  func (m ClientDelegate) Receive() (seq base.Seq, result base.Result, err error) {
   155  	vals, err := m.Call("Receive")
   156  	if err != nil {
   157  		panic(err)
   158  	}
   159  	seq, _ = vals[0].(base.Seq)
   160  	result, _ = vals[1].(base.Result)
   161  	err, _ = vals[2].(error)
   162  	return
   163  }
   164  
   165  func (m ClientDelegate) Close() (err error) {
   166  	vals, err := m.Call("Close")
   167  	if err != nil {
   168  		panic(err)
   169  	}
   170  	err, _ = vals[0].(error)
   171  	return
   172  }