test

package
v0.0.0-...-dd85a15 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToResult

func ToResult(result interface{}) json.RawMessage

ToResult JSON-marshals the resul. Panics on error.

func Write

func Write(t *testing.T, conn net.Conn, response *types.Response)

Write writes the `response` to the socket.

Types

type AtomicVal

type AtomicVal[T any] struct {
	// contains filtered or unexported fields
}

func (*AtomicVal[T]) Get

func (a *AtomicVal[T]) Get() T

func (*AtomicVal[T]) Set

func (a *AtomicVal[T]) Set(val T)

type Server

type Server struct {
	OnRequest AtomicVal[func(conn net.Conn, request *types.Request) *types.Response]

	Port int
	// contains filtered or unexported fields
}

Server is a TCP server useful for mocking a JSON RPC server.

func NewServer

func NewServer(t *testing.T) *Server

NewServer creates a test server on an arbitrary unused port.

func NewServerUsingPort

func NewServerUsingPort(t *testing.T, port int) *Server

NewServerUsingPort creates a mock server on the given port.

func (*Server) Close

func (s *Server) Close()

Close closes the server. It blocks until all client connections are closed.

func (*Server) SetOnNewClient

func (s *Server) SetOnNewClient(f func(net.Conn))

SetOnNewClient defines a callback that is called when a new client connects to this server.

Jump to

Keyboard shortcuts

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