dispatchtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call[I, O any](runner *Runner, fn *dispatch.Function[I, O], input I) (O, error)

Call calls a dispatch.Function using the specified Runner.

func KeyPair

func KeyPair() (signingKey, verificationKey string)

KeyPair generates a random ed25519 key pair.

The public and private key are base64 encoded, so that they can be passed directly to the various Dispatch components.

func NewServer

func NewServer(handler dispatchserver.Handler) *httptest.Server

NewServer creates a new test Dispatch API server.

func SigningKey

func SigningKey(signingKey string) dispatchserver.EndpointClientOption

SigningKey sets the signing key to use when signing requests bound for the endpoint.

The signing key should be a base64-encoded ed25519.PrivateKey, e.g. one provided by the KeyPair helper function.

Types

type CallRecorder

type CallRecorder struct {
	// contains filtered or unexported fields
}

CallRecorder is a dispatchserver.Handler that captures requests to the Dispatch API.

func (*CallRecorder) Assert

func (r *CallRecorder) Assert(t *testing.T, want ...DispatchRequest)

Assert asserts that specific calls were made to the Dispatch API server, and that specified headers are present.

When validating request headers, Assert checks that the specified headers were present, but allows extra headers on the request. That is, it's not checking for an exact match with headers.

func (*CallRecorder) Handle

func (r *CallRecorder) Handle(ctx context.Context, header http.Header, calls []dispatchproto.Call) ([]dispatchproto.ID, error)

type DispatchRequest

type DispatchRequest struct {
	Header http.Header
	Calls  []dispatchproto.Call
}

DispatchRequest is a request to the Dispatch API captured by a CallRecorder.

type EndpointServer

type EndpointServer struct {
	// contains filtered or unexported fields
}

EndpointServer is a server serving a Dispatch endpoint.

func NewEndpoint

func NewEndpoint(opts ...dispatch.Option) (*dispatch.Dispatch, *EndpointServer, error)

NewEndpoint creates a Dispatch endpoint, like dispatch.New.

Unlike dispatch.New, it starts a test server that serves the endpoint and automatically sets the endpoint URL.

func (*EndpointServer) Client

Client returns a client that can be used to interact with the Dispatch endpoint.

func (*EndpointServer) Close

func (e *EndpointServer) Close()

Close closes the server.

func (*EndpointServer) URL

func (e *EndpointServer) URL() string

URL is the URL of the server.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs functions.

func NewRunner

func NewRunner(functions ...dispatch.AnyFunction) *Runner

NewRunner creates a Runner.

func (*Runner) Register

func (r *Runner) Register(fn dispatch.AnyFunction)

Register registers a function.

func (*Runner) RegisterPrimitive

func (r *Runner) RegisterPrimitive(name string, fn dispatchproto.Function)

RegisterPrimitive registers a primitive function.

func (Runner) RoundTrip

RoundTrip sends a request to a function and returns its response.

func (*Runner) Run

Run runs a function to completion and returns its response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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