Documentation
¶
Overview ¶
Package clienttest provides a minimal JSON-RPC test server for the client package. It is its own package (not a _test.go file) so l1 provider tests can share it, and lives under internal/ so production code cannot import it (it pulls in testing and httptest).
Index ¶
- type TestHandler
- type TestRPCError
- type TestRequest
- type TestServer
- func (ts *TestServer) Close()
- func (ts *TestServer) KillWSConns()
- func (ts *TestServer) PingsReceived() int64
- func (ts *TestServer) PushNotification(ctx context.Context, subID string, payload any) error
- func (ts *TestServer) PushRawFrame(ctx context.Context, data []byte) error
- func (ts *TestServer) SetDropPings(b bool)
- func (ts *TestServer) SetHandler(h TestHandler)
- func (ts *TestServer) URL() string
- func (ts *TestServer) WSConnCount() int
- func (ts *TestServer) WSURL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestHandler ¶
type TestHandler func(req TestRequest) (result any, rerr *TestRPCError)
TestHandler returns the JSON-RPC reply for a request: result becomes "result", or a non-nil rerr becomes "error" (result ignored).
type TestRPCError ¶
type TestRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
Code is required; Data is optional.
type TestRequest ¶
type TestRequest struct {
Method string
Params []json.RawMessage
}
type TestServer ¶
type TestServer struct {
// contains filtered or unexported fields
}
TestServer serves JSON-RPC over POST or a websocket upgrade on the same URL. Live ws conns are tracked so tests can push notifications or sever mid-call.
func NewTestServer ¶
func NewTestServer(tb testing.TB) *TestServer
func (*TestServer) Close ¶
func (ts *TestServer) Close()
func (*TestServer) KillWSConns ¶
func (ts *TestServer) KillWSConns()
func (*TestServer) PingsReceived ¶
func (ts *TestServer) PingsReceived() int64
func (*TestServer) PushNotification ¶
func (*TestServer) PushRawFrame ¶
func (ts *TestServer) PushRawFrame(ctx context.Context, data []byte) error
PushRawFrame writes data verbatim, so tests can inject malformed frames a well-behaved server would never emit.
func (*TestServer) SetDropPings ¶
func (ts *TestServer) SetDropPings(b bool)
SetDropPings makes the server count incoming pings but suppress the pong reply, to provoke client-side ping timeouts.
func (*TestServer) SetHandler ¶
func (ts *TestServer) SetHandler(h TestHandler)
func (*TestServer) URL ¶
func (ts *TestServer) URL() string
func (*TestServer) WSConnCount ¶
func (ts *TestServer) WSConnCount() int
func (*TestServer) WSURL ¶
func (ts *TestServer) WSURL() string