Documentation
¶
Index ¶
- func Call[I, O any](runner *Runner, fn *dispatch.Function[I, O], input I) (O, error)
- func KeyPair() (signingKey, verificationKey string)
- func NewServer(handler dispatchserver.Handler) *httptest.Server
- func SigningKey(signingKey string) dispatchserver.EndpointClientOption
- type CallRecorder
- type DispatchRequest
- type EndpointServer
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
func (e *EndpointServer) Client(opts ...dispatchserver.EndpointClientOption) (*dispatchserver.EndpointClient, error)
Client returns a client that can be used to interact with the Dispatch endpoint.
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 ¶
func (r Runner) RoundTrip(req dispatchproto.Request) dispatchproto.Response
RoundTrip sends a request to a function and returns its response.
func (*Runner) Run ¶
func (r *Runner) Run(req dispatchproto.Request) dispatchproto.Response
Run runs a function to completion and returns its response.