clienttest

package
v0.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 (ts *TestServer) PushNotification(ctx context.Context, subID string, payload any) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL