testutil

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0, MIT Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(options ...Option) (*client.Client, error)

Client creates an entire client.Client with a connection to an in-process server, each configured with the given options.

func ComposeOptions

func ComposeOptions[C any](opts ...func(C)) func(C)

ComposeOptions combines multiple options into one. It's written generically so that it might someday move somewhere more generic, but so far it's only being used here anyhow.

func NewPutClient

func NewPutClient() *http.Client

NewPutClient creates a new mock http.Client that accepts and tracks any PUT request, without making an actual network request.

func NewRetrievalClient

func NewRetrievalClient(t *testing.T, service principal.Signer, testData []byte, opts ...RetrievalClientOption) *http.Client

NewRetrievalClient creates an in-process retrieval server and returns an HTTP client that can connect to it directly (without network I/O). By default, the server validates that: - URL hash (from path /blob/<hash>) - Capability hash (from invocation) - Actual data hash all match before serving the content.

Use WithoutHashValidation() to disable hash validation for testing client-side validation.

func NewTestServerConnection

func NewTestServerConnection(options ...server.Option) uclient.Connection

NewTestServerConnection creates a new Ucanto server and a connection to it. It accepts `server.Option`s to configure the server. This is mainly (if not exclusively) to provide service methods.

The server generates its own service principal. It has a `did:web:` DID for realism and readability in errors and failures, but calling code should use `connection.ID()` to get it rather than assume knowledge of the DID it picks.

func Ptr added in v0.4.0

func Ptr[T any](v T) *T

Ptr returns a pointer to the given value.

func SpaceBlobAddHandler

func SpaceBlobAddHandler(
	rcptIssued func(rcpt receipt.AnyReceipt),
	includePDP bool,
) (server.HandlerFunc[spaceblobcap.AddCaveats, spaceblobcap.AddOk, failure.IPLDBuilderFailure], error)

SpaceBlobAddHandler returns a mock server.HandlerFunc to handles spaceblobcap.Add invocations in a test. rcptIssued is called with each receipt that is issued along the way. If includePDP is true, the accept receipt will include a (random) PDP accept link; otherwise, the PDP accept link will be nil.

func Urls

func Urls(strs ...string) []url.URL

Urls parses strings into url.URLs and panics on error.

Types

type BlobMap

type BlobMap = bytemap.ByteMap[multihash.Multihash, []byte]

func ReceivedBlobs

func ReceivedBlobs(putClient *http.Client) BlobMap

type BlobReceiver

type BlobReceiver interface {
	ReceivedBlobs() BlobMap
}

type ClientWithCustomPut

type ClientWithCustomPut struct {
	*client.Client
	PutClient *http.Client
}

ClientWithCustomPut is a client.Client that uses a custom client for PUT requests from [SpaceBlobAdd].

func (*ClientWithCustomPut) SpaceBlobAdd

func (c *ClientWithCustomPut) SpaceBlobAdd(ctx context.Context, content io.Reader, space did.DID, options ...client.SpaceBlobAddOption) (client.AddedBlob, error)

type Option

type Option func(*clientServerConfig)

func WithClientOptions

func WithClientOptions(opts ...client.Option) Option

WithClientOptions appends options to the client configuration.

func WithServerOptions

func WithServerOptions(opts ...server.Option) Option

WithServerOptions appends options to the server configuration.

func WithSpaceBlobAdd

func WithSpaceBlobAdd() Option

WithSpaceBlobAdd creates an Option that adds `space/blob/add` support to the server. NB: This takes over the receipts client entirely. Currently, different options can't cooperate to share a receipts client. That's solvable, but hasn't been necessary yet.

func WithSpaceBlobAddPDP

func WithSpaceBlobAddPDP() Option

WithSpaceBlobAddPDP is like WithSpaceBlobAdd but includes a PDP accept link in the accept receipt.

type RetrievalClientOption

type RetrievalClientOption func(*retrievalClientConfig)

RetrievalClientOption configures a retrieval client.

func WithoutHashValidation

func WithoutHashValidation() RetrievalClientOption

WithoutHashValidation disables server-side hash validation. This is useful for testing client-side validation.

Jump to

Keyboard shortcuts

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