testutil

package
v0.0.0-...-69aaf77 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0, MIT Imports: 41 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlobAddHandler

func BlobAddHandler(
	t *testing.T,
	serviceID ucan.Issuer,
	rcptIssued func(task cid.Cid, ct ucan.Container),
	includePutReceipt bool,
) server.Route

BlobAddHandler returns a mock server.Route to handle blobcmds.Add invocations in a test. rcptIssued is called with each receipt that is issued along the way. If includePutReceipt is true, a successful http/put receipt is embedded in the response (simulating a blob that was already uploaded).

func Client

func Client(t *testing.T, 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 ucan.Issuer, testData []byte, opts ...RetrievalClientOption) *http.Client

NewRetrievalClient creates an in-process retrieval server and returns an HTTP client that connects to it directly (without network I/O). The server handles `/content/retrieve` invocations, serving the requested byte range of testData. By default it validates that the capability digest (and the URL path hash, when present) match the actual data hash before serving. Use WithoutHashValidation() to disable that for testing client-side validation.

func NewTestServer

func NewTestServer(t *testing.T, options ...server.HTTPOption) (did.DID, *server.HTTPServer)

NewTestServer creates a new Ucanto server. It accepts `server.HTTPOption`s to configure the server.

The server generates its own service principal. It has a `did:web:` DID for realism and readability in errors and failures.

func Ptr

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

Ptr returns a pointer to the given value.

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) BlobAdd

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

type Option

type Option func(*clientServerConfig)

func WithBlobAdd

func WithBlobAdd(t *testing.T) Option

WithBlobAdd creates an Option that adds `/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 WithBlobAddPutReceipt

func WithBlobAddPutReceipt(t *testing.T) Option

WithBlobAddPutReceipt is like WithBlobAdd but includes a successful /http/put receipt in the /blob/add response, simulating a blob that was already uploaded by a previous attempt.

func WithClientOptions

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

WithClientOptions appends options to the client configuration.

func WithServerOptions

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

WithServerOptions appends options to the server configuration.

func WithServerRoutes

func WithServerRoutes(routes ...RouteBuilderFunc) Option

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.

type RouteBuilderFunc

type RouteBuilderFunc func(RouteDeps) server.Route

type RouteDeps

type RouteDeps struct {
	ServiceID ucan.Issuer
}

Jump to

Keyboard shortcuts

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