Documentation
¶
Index ¶
- Constants
- func AssertS3Error(t testing.TB, expected s3errs.Error, got error)
- func AssertS3StatusCode(t testing.TB, expected s3errs.Error, got error)
- func NewBackend(t testing.TB, opts ...TesterOption) *sia.Sia
- func ObjectIdentifiers(keys ...string) []types.ObjectIdentifier
- type MemorySDK
- func (s *MemorySDK) DeleteObject(_ context.Context, id types.Hash256) error
- func (s *MemorySDK) Download(obj sdk.Object, rnge *s3.ObjectRange) (io.ReadCloser, error)
- func (s *MemorySDK) ObjectCount() int
- func (s *MemorySDK) ObjectEvents(_ context.Context, cursor slabs.Cursor, limit int) ([]sdk.ObjectEvent, error)
- func (s *MemorySDK) OptimalDataSize() (int64, error)
- func (s *MemorySDK) PinObject(_ context.Context, obj sdk.Object) error
- func (s *MemorySDK) PruneSlabs(_ context.Context, opts ...api.URLQueryParameterOption) error
- func (s *MemorySDK) PruneSlabsCalls() int
- func (s *MemorySDK) SealObject(obj sdk.Object) sdk.SealedObject
- func (s *MemorySDK) SetEvents(events []sdk.ObjectEvent)
- func (s *MemorySDK) SetSlabSize(size int64)
- func (s *MemorySDK) UnsealObject(sealed sdk.SealedObject) (sdk.Object, error)
- func (s *MemorySDK) Upload(_ context.Context, r io.Reader) (sdk.Object, error)
- func (s *MemorySDK) UploadPacked() (sia.PackedUpload, error)
- type S3Tester
- func (t *S3Tester) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string) error
- func (t *S3Tester) AddObject(bucket, object string, data []byte, metadata map[string]string) error
- func (t *S3Tester) BucketLocation(ctx context.Context, bucket string) (string, error)
- func (t *S3Tester) ChangeAccessKey(tb testing.TB, accessKeyID, secretKey string) *S3Tester
- func (t *S3Tester) Client() *service.Client
- func (t *S3Tester) CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, ...) (*service.CompleteMultipartUploadOutput, error)
- func (t *S3Tester) CopyObject(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject string, ...) ([]byte, error)
- func (t *S3Tester) CreateBucket(ctx context.Context, bucket string) error
- func (t *S3Tester) CreateMultipartUpload(ctx context.Context, bucket, object string, meta map[string]string) (*service.CreateMultipartUploadOutput, error)
- func (t *S3Tester) DeleteBucket(ctx context.Context, bucket string) error
- func (t *S3Tester) DeleteObject(ctx context.Context, bucket, object string) error
- func (t *S3Tester) DeleteObjects(ctx context.Context, bucket string, objects []types.ObjectIdentifier, ...) (*service.DeleteObjectsOutput, error)
- func (t *S3Tester) GetObject(ctx context.Context, bucket, object string, rnge *s3.ObjectRangeRequest) (*s3.Object, error)
- func (t *S3Tester) GetObjectPart(ctx context.Context, bucket, object string, partNumber int32) (*s3.Object, error)
- func (t *S3Tester) HeadBucket(ctx context.Context, bucket string) error
- func (t *S3Tester) HeadObject(ctx context.Context, bucket, object string, rnge *s3.ObjectRangeRequest) (*s3.Object, error)
- func (t *S3Tester) HeadObjectPart(ctx context.Context, bucket, object string, partNumber int32) (*s3.Object, error)
- func (t *S3Tester) ListBuckets(ctx context.Context) ([]types.Bucket, error)
- func (t *S3Tester) ListMultipartUploads(ctx context.Context, bucket string, input *service.ListMultipartUploadsInput) (*service.ListMultipartUploadsOutput, error)
- func (t *S3Tester) ListObjectVersions(ctx context.Context, bucket string, prefix, delimiter *string, ...) (*service.ListObjectVersionsOutput, error)
- func (t *S3Tester) ListObjects(ctx context.Context, bucket string, prefix, delimiter *string, ...) (*service.ListObjectsOutput, error)
- func (t *S3Tester) ListObjectsV2(ctx context.Context, bucket string, prefix, delimiter *string, ...) (*service.ListObjectsV2Output, error)
- func (t *S3Tester) ListParts(ctx context.Context, bucket, object, uploadID string, marker *string, ...) (*service.ListPartsOutput, error)
- func (t *S3Tester) PutObject(ctx context.Context, bucket, object string, r io.Reader, ...) ([]byte, error)
- func (t *S3Tester) UploadPart(ctx context.Context, bucket, object, uploadID string, partNumber int32, ...) (*service.UploadPartOutput, error)
- func (t *S3Tester) UploadPartCopy(ctx context.Context, ...) (*service.UploadPartCopyOutput, error)
- type TesterOption
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
OptimalDataSize returns the optimal data size.
func (*MemorySDK) PruneSlabs ¶
PruneSlabs prunes slabs not associated with an object from the indexer.
func (*MemorySDK) PruneSlabsCalls ¶
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 ¶
SetSlabSize overrides the slab size for testing.
func (*MemorySDK) UnsealObject ¶
UnsealObject unseals an object using the app key.
func (*MemorySDK) Upload ¶
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 ¶
AbortMultipartUpload is a convenience wrapper around the AWS SDK's AbortMultipartUpload API.
func (*S3Tester) BucketLocation ¶
BucketLocation gets the location of an S3 bucket.
func (*S3Tester) ChangeAccessKey ¶
ChangeAccessKey creates a copy of the tester that uses the provided keypair to access the S3 API.
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 ¶
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 ¶
DeleteBucket deletes an S3 bucket.
func (*S3Tester) DeleteObject ¶
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 ¶
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 ¶
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.