Documentation
¶
Index ¶
- func NewTmpTunnel(t time.Duration) (*jsonrpc.Tunnel, *ConnRecorder, *ReqRecorder)
- type ConnRecorder
- func (recorder *ConnRecorder) Close() error
- func (recorder *ConnRecorder) CloseAfter(dur time.Duration)
- func (recorder *ConnRecorder) Get(idx int) []byte
- func (recorder *ConnRecorder) GetAll() [][]byte
- func (recorder *ConnRecorder) GetAllRequests() ([]*jsonrpc.Request, error)
- func (recorder *ConnRecorder) GetRequest(idx int) (*jsonrpc.Request, error)
- func (recorder *ConnRecorder) GetResponse(idx int) (*jsonrpc.Response, error)
- func (recorder *ConnRecorder) Next() ([]byte, error)
- func (recorder *ConnRecorder) PushNext(v interface{}) error
- func (recorder *ConnRecorder) PushNextRaw(data []byte)
- func (recorder *ConnRecorder) PushNextReq(method string, params interface{}) error
- func (recorder *ConnRecorder) Unmarshal(idx int, v interface{}) error
- func (recorder *ConnRecorder) UnmarshalRequestParams(idx int, v interface{}) error
- func (recorder *ConnRecorder) UnmarshalResponseResult(idx int, v interface{}) error
- func (recorder *ConnRecorder) WaitUntil(p NativeConnWaitPredicate) error
- func (recorder *ConnRecorder) Write(body []byte) error
- type NativeConnWaitPredicate
- type ReqRecorder
- func (recorder *ReqRecorder) Call(tun *jsonrpc.Tunnel, params interface{}, rt jsonrpc.RespTransmitter)
- func (recorder *ReqRecorder) Close()
- func (recorder *ReqRecorder) CloseAfter(dur time.Duration)
- func (recorder *ReqRecorder) FindHandler(method string) (jsonrpc.MethodHandler, bool)
- func (recorder *ReqRecorder) Get(idx int) (*jsonrpc.Request, jsonrpc.RespTransmitter)
- func (recorder *ReqRecorder) Unmarshal(params []byte) (interface{}, error)
- func (recorder *ReqRecorder) WaitUntil(p ReqRecorderWaitPredicate) error
- type ReqRecorderWaitPredicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTmpTunnel ¶
func NewTmpTunnel(t time.Duration) (*jsonrpc.Tunnel, *ConnRecorder, *ReqRecorder)
NewTmpTunnel creates a new running jsonrpc.Tunnel based on test connection and test request dispatcher which will be automatically closed after specified timeout.
Types ¶
type ConnRecorder ¶
type ConnRecorder struct {
// contains filtered or unexported fields
}
ConnRecorder is a fake connection which records all writes and provides functionality to push reads.
func NewConnRecorder ¶
func NewConnRecorder() *ConnRecorder
NewConnRecorder returns a new conn recorder.
func (*ConnRecorder) Close ¶
func (recorder *ConnRecorder) Close() error
Close closes this recorder, so all the waiters wake up and receive an error.
func (*ConnRecorder) CloseAfter ¶
func (recorder *ConnRecorder) CloseAfter(dur time.Duration)
CloseAfter closes this request after specified timeout.
func (*ConnRecorder) Get ¶
func (recorder *ConnRecorder) Get(idx int) []byte
Get returns bytes which were wrote (idx+1)th to this connection.
func (*ConnRecorder) GetAll ¶
func (recorder *ConnRecorder) GetAll() [][]byte
GetAll returns all captured writes.
func (*ConnRecorder) GetAllRequests ¶
func (recorder *ConnRecorder) GetAllRequests() ([]*jsonrpc.Request, error)
GetAllRequests goes through all captured data tries to unmarshal it to the requests and then returns the result. Result will contains only those requests which method is different from "".
func (*ConnRecorder) GetRequest ¶
func (recorder *ConnRecorder) GetRequest(idx int) (*jsonrpc.Request, error)
GetRequest gets bytes wrote (idx+1)th and unmarshals them as *jsonrpc.Request.
func (*ConnRecorder) GetResponse ¶
func (recorder *ConnRecorder) GetResponse(idx int) (*jsonrpc.Response, error)
GetResponse gets bytes wrote (idx+1)th and unmarshals them as *jsonrpc.Response.
func (*ConnRecorder) Next ¶
func (recorder *ConnRecorder) Next() ([]byte, error)
Next returns bytes pushed by one of Push* functions.
func (*ConnRecorder) PushNext ¶
func (recorder *ConnRecorder) PushNext(v interface{}) error
PushNext marshals a given value to json and pushes marshaled data to the read channel as PushNextRaw func does.
func (*ConnRecorder) PushNextRaw ¶
func (recorder *ConnRecorder) PushNextRaw(data []byte)
PushNextRaw pushes marshaled data to the read channel, so if Next() is called the data is returned.
func (*ConnRecorder) PushNextReq ¶
func (recorder *ConnRecorder) PushNextReq(method string, params interface{}) error
PushNextReq marshals a given method and params as requests and pushes it using PushNextRaw.
func (*ConnRecorder) Unmarshal ¶
func (recorder *ConnRecorder) Unmarshal(idx int, v interface{}) error
Unmarshal parses bytes wrote (idx+1)th and applies it on given value.
func (*ConnRecorder) UnmarshalRequestParams ¶
func (recorder *ConnRecorder) UnmarshalRequestParams(idx int, v interface{}) error
UnmarshalRequestParams unmarshals request.Params wrote (idx+1)th to a given value.
func (*ConnRecorder) UnmarshalResponseResult ¶
func (recorder *ConnRecorder) UnmarshalResponseResult(idx int, v interface{}) error
UnmarshalResponseResult unmarshals response.Result wrote (idx+1)th to a given value.
func (*ConnRecorder) WaitUntil ¶
func (recorder *ConnRecorder) WaitUntil(p NativeConnWaitPredicate) error
WaitUntil waits until either recorder is closed or predicate returned true, if closed before predicate condition is met, error is returned.
func (*ConnRecorder) Write ¶
func (recorder *ConnRecorder) Write(body []byte) error
Write captures given bytes.
type NativeConnWaitPredicate ¶
type NativeConnWaitPredicate func(recorder *ConnRecorder) bool
NativeConnWaitPredicate is used to wait on recorder until the condition behind this predicate is met.
func ReqSent ¶
func ReqSent(method string) NativeConnWaitPredicate
ReqSent is a predicate that waits until a given method is requested.
func WriteCalledAtLeast ¶
func WriteCalledAtLeast(times int) NativeConnWaitPredicate
WriteCalledAtLeast is a predicate that allows to wait until write is called at least given number of times.
type ReqRecorder ¶
type ReqRecorder struct {
// contains filtered or unexported fields
}
ReqRecorder helps to catch/record jsonrpc.Tunnel incoming requests.
func (*ReqRecorder) Call ¶
func (recorder *ReqRecorder) Call(tun *jsonrpc.Tunnel, params interface{}, rt jsonrpc.RespTransmitter)
Call records a call of method handler.
func (*ReqRecorder) Close ¶
func (recorder *ReqRecorder) Close()
Close closes this recorder all waiters will be notified about close and WaitUntil will return errors for them.
func (*ReqRecorder) CloseAfter ¶
func (recorder *ReqRecorder) CloseAfter(dur time.Duration)
CloseAfter closes this request after specified timeout.
func (*ReqRecorder) FindHandler ¶
func (recorder *ReqRecorder) FindHandler(method string) (jsonrpc.MethodHandler, bool)
FindHandler returns this recorder.
func (*ReqRecorder) Get ¶
func (recorder *ReqRecorder) Get(idx int) (*jsonrpc.Request, jsonrpc.RespTransmitter)
Get returns request + response transmitter which were caught (idx+1)th.
func (*ReqRecorder) Unmarshal ¶
func (recorder *ReqRecorder) Unmarshal(params []byte) (interface{}, error)
Unmarshal returns given params.
func (*ReqRecorder) WaitUntil ¶
func (recorder *ReqRecorder) WaitUntil(p ReqRecorderWaitPredicate) error
WaitUntil waits until either recorder is closed or predicate returned true, if closed before predicate returned true, error is returned.
type ReqRecorderWaitPredicate ¶
type ReqRecorderWaitPredicate func(req *ReqRecorder) bool
ReqRecorderWaitPredicate is used to wait on recorder until the condition behind this predicate is met.
func ResponseArrivedAtLeast ¶
func ResponseArrivedAtLeast(times int) ReqRecorderWaitPredicate
ResponseArrivedAtLeast is a predicate that allows to wait until write is called at least given number of times.