Documentation
¶
Index ¶
- func BlobAddHandler(t *testing.T, serviceID ucan.Issuer, ...) server.Route
- func Client(t *testing.T, options ...Option) (*client.Client, error)
- func ComposeOptions[C any](opts ...func(C)) func(C)
- func NewPutClient() *http.Client
- func NewRetrievalClient(t *testing.T, service ucan.Issuer, testData []byte, ...) *http.Client
- func NewTestServer(t *testing.T, options ...server.HTTPOption) (did.DID, *server.HTTPServer)
- func Ptr[T any](v T) *T
- func Urls(strs ...string) []url.URL
- type BlobMap
- type BlobReceiver
- type ClientWithCustomPut
- type Option
- type RetrievalClientOption
- type RouteBuilderFunc
- type RouteDeps
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 ¶
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 ¶
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.
Types ¶
type BlobMap ¶
func ReceivedBlobs ¶
type BlobReceiver ¶
type BlobReceiver interface {
ReceivedBlobs() BlobMap
}
type ClientWithCustomPut ¶
ClientWithCustomPut is a client.Client that uses a custom client for PUT requests from [SpaceBlobAdd].
type Option ¶
type Option func(*clientServerConfig)
func WithBlobAdd ¶
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 ¶
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 ¶
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.