github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/rpc/client/mock_test.go (about) 1 package client 2 3 import ( 4 "context" 5 6 types "github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/types" 7 ) 8 9 type ( 10 sendRequestDelegate func(context.Context, types.RPCRequest) (*types.RPCResponse, error) 11 sendBatchDelegate func(context.Context, types.RPCRequests) (types.RPCResponses, error) 12 closeDelegate func() error 13 ) 14 15 type mockClient struct { 16 sendRequestFn sendRequestDelegate 17 sendBatchFn sendBatchDelegate 18 closeFn closeDelegate 19 } 20 21 func (m *mockClient) SendRequest(ctx context.Context, request types.RPCRequest) (*types.RPCResponse, error) { 22 if m.sendRequestFn != nil { 23 return m.sendRequestFn(ctx, request) 24 } 25 26 return nil, nil 27 } 28 29 func (m *mockClient) SendBatch(ctx context.Context, requests types.RPCRequests) (types.RPCResponses, error) { 30 if m.sendBatchFn != nil { 31 return m.sendBatchFn(ctx, requests) 32 } 33 34 return nil, nil 35 } 36 37 func (m *mockClient) Close() error { 38 if m.closeFn != nil { 39 return m.closeFn() 40 } 41 42 return nil 43 }