testutil

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testutil provides shared test infrastructure for SynapS3 packages. It is only compiled and linked in test binaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestDB

func NewTestDB(t *testing.T) *bun.DB

NewTestDB creates a fresh in-memory SQLite DB with all migrations applied. The database is closed automatically when the test completes.

func NewTestFileDB

func NewTestFileDB(t *testing.T) *bun.DB

NewTestFileDB creates a fresh file-backed SQLite DB with all migrations applied. Use it for tests that cancel database contexts while worker goroutines are active.

func NewTestRepos

func NewTestRepos(t *testing.T) *repository.Repositories

NewTestRepos creates a Repositories instance backed by an in-memory SQLite DB.

func SeedBucket

func SeedBucket(t *testing.T, db *bun.DB, name string) *model.Bucket

SeedBucket inserts an active bucket and returns it.

func SeedBucketWithStatus

func SeedBucketWithStatus(t *testing.T, db *bun.DB, name string, status model.BucketStatus) *model.Bucket

SeedBucketWithStatus inserts a bucket with the specified status.

Types

type MockCache

type MockCache struct {
	PutFunc             func(ctx context.Context, bucket, key string, r io.Reader) (*cache.ObjectInfo, error)
	PutStagedFunc       func(ctx context.Context, bucket, key string, r io.Reader) (*cache.StagedObject, error)
	GetFunc             func(ctx context.Context, bucket, key string) (io.ReadCloser, *cache.ObjectInfo, error)
	DeleteFunc          func(ctx context.Context, bucket, key string) error
	ExistsFunc          func(ctx context.Context, bucket, key string) bool
	UsedBytesFunc       func() int64
	CreateBucketDirFunc func(ctx context.Context, bucket string) error
	DeleteBucketDirFunc func(ctx context.Context, bucket string) error
	PutPartFunc         func(ctx context.Context, uploadID string, partNumber int, r io.Reader) (*cache.ObjectInfo, error)
	AssemblePartsFunc   func(ctx context.Context, bucket, key, uploadID string, partNumbers []int) (*cache.ObjectInfo, []string, error)
	DeleteUploadFunc    func(ctx context.Context, uploadID string) error
}

MockCache is a configurable test double for cache.Cache. Use for fault injection tests; for happy-path tests prefer real cache.NewFilesystem.

func (*MockCache) AssembleParts

func (m *MockCache) AssembleParts(ctx context.Context, bucket, key, uploadID string, partNumbers []int) (*cache.ObjectInfo, []string, error)

func (*MockCache) CreateBucketDir

func (m *MockCache) CreateBucketDir(ctx context.Context, bucket string) error

func (*MockCache) Delete

func (m *MockCache) Delete(ctx context.Context, bucket, key string) error

func (*MockCache) DeleteBucketDir

func (m *MockCache) DeleteBucketDir(ctx context.Context, bucket string) error

func (*MockCache) DeleteUpload

func (m *MockCache) DeleteUpload(ctx context.Context, uploadID string) error

func (*MockCache) Exists

func (m *MockCache) Exists(ctx context.Context, bucket, key string) bool

func (*MockCache) Get

func (m *MockCache) Get(ctx context.Context, bucket, key string) (io.ReadCloser, *cache.ObjectInfo, error)

func (*MockCache) Put

func (m *MockCache) Put(ctx context.Context, bucket, key string, r io.Reader) (*cache.ObjectInfo, error)

func (*MockCache) PutPart

func (m *MockCache) PutPart(ctx context.Context, uploadID string, partNumber int, r io.Reader) (*cache.ObjectInfo, error)

func (*MockCache) PutStaged

func (m *MockCache) PutStaged(ctx context.Context, bucket, key string, r io.Reader) (*cache.StagedObject, error)

func (*MockCache) UsedBytes

func (m *MockCache) UsedBytes() int64

type MockChainEpochReader

type MockChainEpochReader struct {
	CurrentEpochFunc func(ctx context.Context) (int64, error)
}

MockChainEpochReader is a configurable test double for synapse.ChainEpochReader. An unconfigured reader reports epoch zero, which keeps a retirement gate waiting rather than letting it pass by accident.

func (*MockChainEpochReader) CurrentEpoch

func (m *MockChainEpochReader) CurrentEpoch(ctx context.Context) (int64, error)

type MockServiceTerminator

type MockServiceTerminator struct {
	TerminateServiceFunc func(ctx context.Context, dataSetID sdktypes.BigInt) (*synapse.TerminationResult, error)
}

MockServiceTerminator is a configurable test double for synapse.ServiceTerminator.

func (*MockServiceTerminator) TerminateService

func (m *MockServiceTerminator) TerminateService(ctx context.Context, dataSetID sdktypes.BigInt) (*synapse.TerminationResult, error)

type MockStorageClient

type MockStorageClient struct {
	UploadFunc              func(ctx context.Context, r io.Reader, opts *storage.UploadOptions) (*storage.UploadResult, error)
	DownloadFunc            func(ctx context.Context, pieceCID cid.Cid, opts *storage.DownloadOptions) (io.ReadCloser, error)
	PrepareUploadFunc       func(ctx context.Context, dataSize uint64, targets []synapse.StorageTarget) (*storage.MultiContextCosts, error)
	SelectUploadTargetsFunc func(ctx context.Context, opts storage.SelectUploadContextsOptions) ([]synapse.StorageTarget, error)
	OpenProviderTargetFunc  func(ctx context.Context, providerID sdktypes.BigInt, opts storage.NewProviderContextOptions) (synapse.ProviderTarget, error)
	OpenDataSetTargetFunc   func(ctx context.Context, dataSetID sdktypes.BigInt, opts storage.NewDataSetContextOptions) (synapse.DataSetTarget, error)
	OpenTargetFunc          func(ctx context.Context, opts *OpenTargetOptions) (synapse.StorageTarget, error)
	FindMatchingDataSetFunc func(ctx context.Context, providerID sdktypes.BigInt, metadata map[string]string, withCDN bool) (*storage.DataSetRef, error)
	OpenCleanupContextFunc  func(ctx context.Context, dataSetID sdktypes.BigInt, opts storage.NewDataSetContextOptions) (synapse.CleanupContext, error)
}

MockStorageClient is a configurable test double for synapse.StorageClient.

func (*MockStorageClient) Download

func (m *MockStorageClient) Download(ctx context.Context, pieceCID cid.Cid, opts *storage.DownloadOptions) (io.ReadCloser, error)

func (*MockStorageClient) FindMatchingDataSet

func (m *MockStorageClient) FindMatchingDataSet(ctx context.Context, providerID sdktypes.BigInt, metadata map[string]string, withCDN bool) (*storage.DataSetRef, error)

func (*MockStorageClient) OpenCleanupContext

func (*MockStorageClient) OpenDataSetTarget

func (*MockStorageClient) OpenProviderTarget

func (*MockStorageClient) PrepareUpload

func (m *MockStorageClient) PrepareUpload(ctx context.Context, dataSize uint64, targets []synapse.StorageTarget) (*storage.MultiContextCosts, error)

func (*MockStorageClient) SelectUploadTargets

func (*MockStorageClient) Upload

type MockStorageTarget

type MockStorageTarget struct {
	ProviderIDValue      sdktypes.BigInt
	DataSetIDValue       *sdktypes.BigInt
	ClientDataSetIDValue sdktypes.BigInt
	ServiceURLValue      string
	WithCDNValue         bool
	PresignForCommitFunc func(context.Context, []storage.PieceInput) ([]byte, error)
	SubmitCommitFunc     func(context.Context, storage.CommitRequest) (*storage.CommitSubmission, error)
	GetCommitStatusFunc  func(context.Context, storage.CommitSubmission) (*storage.CommitStatus, error)
	PieceStatusFunc      func(context.Context, cid.Cid) (*storage.PieceStatus, error)
}

MockStorageTarget is a minimal immutable storage target for tests that only need provider metadata for upload preparation.

func NewMockDataSetTarget

func NewMockDataSetTarget(providerID, dataSetID sdktypes.BigInt, withCDN *bool) *MockStorageTarget

func NewMockProviderTarget

func NewMockProviderTarget(providerID sdktypes.BigInt, opts storage.NewProviderContextOptions) *MockStorageTarget

func (*MockStorageTarget) CDNEnabled

func (m *MockStorageTarget) CDNEnabled() bool

func (*MockStorageTarget) ClientDataSetID

func (m *MockStorageTarget) ClientDataSetID() sdktypes.BigInt

func (*MockStorageTarget) DataSetRef

func (m *MockStorageTarget) DataSetRef() (storage.DataSetRef, bool)

func (*MockStorageTarget) GetCommitStatus

func (m *MockStorageTarget) GetCommitStatus(ctx context.Context, submission storage.CommitSubmission) (*storage.CommitStatus, error)

func (*MockStorageTarget) GetProviderInfo

func (m *MockStorageTarget) GetProviderInfo() storage.Provider

func (*MockStorageTarget) PieceStatus

func (m *MockStorageTarget) PieceStatus(ctx context.Context, pieceCID cid.Cid) (*storage.PieceStatus, error)

func (*MockStorageTarget) PieceURL

func (m *MockStorageTarget) PieceURL(piece cid.Cid) string

func (*MockStorageTarget) PresignForCommit

func (m *MockStorageTarget) PresignForCommit(ctx context.Context, pieces []storage.PieceInput) ([]byte, error)

func (*MockStorageTarget) ProviderID

func (m *MockStorageTarget) ProviderID() sdktypes.BigInt

func (*MockStorageTarget) Pull

func (*MockStorageTarget) ServiceURL

func (m *MockStorageTarget) ServiceURL() string

func (*MockStorageTarget) Store

func (*MockStorageTarget) SubmitCommit

type MockWalletQuerier

type MockWalletQuerier struct {
	GetWalletInfoFunc func(ctx context.Context) (*synapse.WalletInfo, error)
}

MockWalletQuerier is a configurable test double for synapse.WalletQuerier.

func (*MockWalletQuerier) GetWalletInfo

func (m *MockWalletQuerier) GetWalletInfo(ctx context.Context) (*synapse.WalletInfo, error)

type OpenTargetOptions

type OpenTargetOptions struct {
	ProviderID      *sdktypes.BigInt
	DataSetID       *sdktypes.BigInt
	DataSetMetadata map[string]string
	WithCDN         *bool
}

OpenTargetOptions lets worker tests configure one callback for both immutable provider and data-set target opens.

Jump to

Keyboard shortcuts

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