testutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AccessKeyID is the access key configured for S3Tester
	AccessKeyID = "AKIA7GQ3XN52WQLYDHZP"

	// SecretAccessKey is the secret key configured for S3Tester
	SecretAccessKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

	// Owner is the default owner name for objects created by S3Tester
	Owner = "s3tester"
)

Variables

This section is empty.

Functions

func AssertS3Error

func AssertS3Error(t testing.TB, expected s3errs.Error, got error)

AssertS3Error is a helper to check an error returned from the AWS SDK against an expected s3.S3Error. Unfortunately the SDK doesn't expose its internal error type so reflection is not an option and we need to extract the status code from the string.

func AssertS3StatusCode

func AssertS3StatusCode(t testing.TB, expected s3errs.Error, got error)

AssertS3StatusCode is similar to AssertS3Error but meant to be used for responses from HEAD endpoints which can't return the full error.

func NewBackend

func NewBackend(t testing.TB, opts ...TesterOption) *sia.Sia

NewBackend creates a Sia backend backed by an in-memory SDK and a SQLite store in a temporary directory. The default test key pair as well as any key pairs provided via WithKeyPair are registered with the backend.

func ObjectIdentifiers

func ObjectIdentifiers(keys ...string) []types.ObjectIdentifier

ObjectIdentifiers is a convenience function to create a slice of ObjectIdentifiers from object keys.

Types

type MemorySDK

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

MemorySDK is an in-memory implementation of the sia.SDK interface for testing the Sia backend without requiring a full indexer.

func NewMemorySDK

func NewMemorySDK() *MemorySDK

NewMemorySDK creates a new in-memory SDK for testing.

func (*MemorySDK) DeleteObject

func (s *MemorySDK) DeleteObject(_ context.Context, id types.Hash256) error

DeleteObject deletes the object with the given key.

func (*MemorySDK) Download

func (s *MemorySDK) Download(obj sdk.Object, rnge *s3.ObjectRange) (io.ReadCloser, error)

Download downloads an object.

func (*MemorySDK) ObjectCount

func (s *MemorySDK) ObjectCount() int

ObjectCount returns the number of objects stored in the SDK.

func (*MemorySDK) ObjectEvents

func (s *MemorySDK) ObjectEvents(_ context.Context, cursor slabs.Cursor, limit int) ([]sdk.ObjectEvent, error)

ObjectEvents returns object events starting from the given cursor, up to the given limit.

func (*MemorySDK) OptimalDataSize

func (s *MemorySDK) OptimalDataSize() (int64, error)

OptimalDataSize returns the optimal data size.

func (*MemorySDK) PinObject

func (s *MemorySDK) PinObject(_ context.Context, obj sdk.Object) error

PinObject pins the given object.

func (*MemorySDK) PruneSlabs

func (s *MemorySDK) PruneSlabs(_ context.Context, opts ...api.URLQueryParameterOption) error

PruneSlabs prunes slabs not associated with an object from the indexer.

func (*MemorySDK) PruneSlabsCalls

func (s *MemorySDK) PruneSlabsCalls() int

PruneSlabsCalls returns the number of times PruneSlabs has been invoked.

func (*MemorySDK) SealObject

func (s *MemorySDK) SealObject(obj sdk.Object) sdk.SealedObject

SealObject seals the object using the app key.

func (*MemorySDK) SetEvents

func (s *MemorySDK) SetEvents(events []sdk.ObjectEvent)

SetEvents replaces the events returned by ObjectEvents.

func (*MemorySDK) SetSlabSize

func (s *MemorySDK) SetSlabSize(size int64)

SetSlabSize overrides the slab size for testing.

func (*MemorySDK) UnsealObject

func (s *MemorySDK) UnsealObject(sealed sdk.SealedObject) (sdk.Object, error)

UnsealObject unseals an object using the app key.

func (*MemorySDK) Upload

func (s *MemorySDK) Upload(_ context.Context, r io.Reader) (sdk.Object, error)

Upload stores an object in memory. It is not part of the SDK interface but used by tests to simulate the background upload to Sia.

func (*MemorySDK) UploadPacked

func (s *MemorySDK) UploadPacked() (sia.PackedUpload, error)

UploadPacked creates a new packed upload.

type S3Tester

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

S3Tester wraps an AWS S3 client configured to talk to an S3 backend.

func NewCustomTester

func NewCustomTester(t testing.TB, dir string, store sia.Store, sdk sia.SDK, log *zap.Logger, opts ...TesterOption) *S3Tester

NewCustomTester creates a new S3Tester using a Sia backend built from the provided store and SDK.

func NewTester

func NewTester(t testing.TB, opts ...TesterOption) *S3Tester

NewTester creates a new S3Tester and a AWS client configured to talk to it.

func (*S3Tester) AbortMultipartUpload

func (t *S3Tester) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string) error

AbortMultipartUpload is a convenience wrapper around the AWS SDK's AbortMultipartUpload API.

func (*S3Tester) AddObject

func (t *S3Tester) AddObject(bucket, object string, data []byte, metadata map[string]string) error

AddObject adds an object to the S3 backend.

func (*S3Tester) BucketLocation

func (t *S3Tester) BucketLocation(ctx context.Context, bucket string) (string, error)

BucketLocation gets the location of an S3 bucket.

func (*S3Tester) ChangeAccessKey

func (t *S3Tester) ChangeAccessKey(tb testing.TB, accessKeyID, secretKey string) *S3Tester

ChangeAccessKey creates a copy of the tester that uses the provided keypair to access the S3 API.

func (*S3Tester) Client

func (t *S3Tester) Client() *service.Client

Client returns the tester's S3 client.

func (*S3Tester) CompleteMultipartUpload

func (t *S3Tester) CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, parts []types.CompletedPart) (*service.CompleteMultipartUploadOutput, error)

CompleteMultipartUpload is a convenience wrapper around the AWS SDK's CompleteMultipartUpload API.

func (*S3Tester) CopyObject

func (t *S3Tester) CopyObject(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject string, dir types.MetadataDirective, meta map[string]string) ([]byte, error)

CopyObject is a convenience wrapper around the AWS SDK's CopyObject API.

func (*S3Tester) CreateBucket

func (t *S3Tester) CreateBucket(ctx context.Context, bucket string) error

CreateBucket creates a new S3 bucket.

func (*S3Tester) CreateMultipartUpload

func (t *S3Tester) CreateMultipartUpload(ctx context.Context, bucket, object string, meta map[string]string) (*service.CreateMultipartUploadOutput, error)

CreateMultipartUpload is a convenience wrapper around the AWS SDK's CreateMultipartUpload API.

func (*S3Tester) DeleteBucket

func (t *S3Tester) DeleteBucket(ctx context.Context, bucket string) error

DeleteBucket deletes an S3 bucket.

func (*S3Tester) DeleteObject

func (t *S3Tester) DeleteObject(ctx context.Context, bucket, object string) error

DeleteObject deletes an S3 object.

func (*S3Tester) DeleteObjects

func (t *S3Tester) DeleteObjects(ctx context.Context, bucket string, objects []types.ObjectIdentifier, quiet *bool) (*service.DeleteObjectsOutput, error)

DeleteObjects deletes multiple S3 objects at once. If quiet is set to true, the response will only contain errors.

func (*S3Tester) GetObject

func (t *S3Tester) GetObject(ctx context.Context, bucket, object string, rnge *s3.ObjectRangeRequest) (*s3.Object, error)

GetObject is a convenience wrapper around the AWS SDK's GetObject API.

func (*S3Tester) GetObjectPart

func (t *S3Tester) GetObjectPart(ctx context.Context, bucket, object string, partNumber int32) (*s3.Object, error)

GetObjectPart is a convenience wrapper around the AWS SDK's GetObject API that allows specifying a part to download.

func (*S3Tester) HeadBucket

func (t *S3Tester) HeadBucket(ctx context.Context, bucket string) error

HeadBucket is a convenience wrapper around the AWS SDK's HeadBucket API.

func (*S3Tester) HeadObject

func (t *S3Tester) HeadObject(ctx context.Context, bucket, object string, rnge *s3.ObjectRangeRequest) (*s3.Object, error)

HeadObject is a convenience wrapper around the AWS SDK's HeadObject API.

func (*S3Tester) HeadObjectPart

func (t *S3Tester) HeadObjectPart(ctx context.Context, bucket, object string, partNumber int32) (*s3.Object, error)

HeadObjectPart is a convenience wrapper around the AWS SDK's HeadObject API that allows specifying a part.

func (*S3Tester) ListBuckets

func (t *S3Tester) ListBuckets(ctx context.Context) ([]types.Bucket, error)

ListBuckets lists all S3 buckets of the authenticated user.

func (*S3Tester) ListMultipartUploads

func (t *S3Tester) ListMultipartUploads(ctx context.Context, bucket string, input *service.ListMultipartUploadsInput) (*service.ListMultipartUploadsOutput, error)

ListMultipartUploads is a convenience wrapper around the AWS SDK's ListMultipartUploads API.

func (*S3Tester) ListObjectVersions

func (t *S3Tester) ListObjectVersions(ctx context.Context, bucket string, prefix, delimiter *string, page s3.ListObjectsPage) (*service.ListObjectVersionsOutput, error)

ListObjectVersions is a convenience wrapper around the AWS SDK's ListObjectVersions API.

func (*S3Tester) ListObjects

func (t *S3Tester) ListObjects(ctx context.Context, bucket string, prefix, delimiter *string, page s3.ListObjectsPage) (*service.ListObjectsOutput, error)

ListObjects is a convenience wrapper around the AWS SDK's ListObjects (v1) API.

func (*S3Tester) ListObjectsV2

func (t *S3Tester) ListObjectsV2(ctx context.Context, bucket string, prefix, delimiter *string, page s3.ListObjectsPage) (*service.ListObjectsV2Output, error)

ListObjectsV2 is a convenience wrapper around the AWS SDK's ListObjectsV2 API.

func (*S3Tester) ListParts

func (t *S3Tester) ListParts(ctx context.Context, bucket, object, uploadID string, marker *string, maxParts *int32) (*service.ListPartsOutput, error)

ListParts lists uploaded parts for an in-progress multipart upload.

func (*S3Tester) PutObject

func (t *S3Tester) PutObject(ctx context.Context, bucket, object string, r io.Reader, meta map[string]string) ([]byte, error)

PutObject is a convenience wrapper around the AWS SDK's PutObject API.

func (*S3Tester) UploadPart

func (t *S3Tester) UploadPart(ctx context.Context, bucket, object, uploadID string, partNumber int32, body []byte) (*service.UploadPartOutput, error)

UploadPart uploads a single part for an existing multipart upload.

func (*S3Tester) UploadPartCopy

func (t *S3Tester) UploadPartCopy(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject, uploadID string, partNumber int32, rnge *s3.ObjectRange) (*service.UploadPartCopyOutput, error)

UploadPartCopy copies a single part from an existing object as part of a multipart upload.

type TesterOption

type TesterOption func(*testerCfg)

TesterOption is an option for configuring the S3Tester.

func WithBackend

func WithBackend(backend s3.Backend) TesterOption

WithBackend sets the S3 backend to use for the tester.

func WithKeyPair

func WithKeyPair(owner, accessKeyID, secretKey string) TesterOption

WithKeyPair registers an additional user and key pair with the backend. It has no effect when an explicit backend is passed to NewTester via WithBackend.

func WithServiceOptions

func WithServiceOptions(opts ...func(*service.Options)) TesterOption

WithServiceOptions adds options to configure the AWS S3 client.

func WithTLS

func WithTLS() TesterOption

WithTLS configures the tester to use TLS.

Jump to

Keyboard shortcuts

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