testutil

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities for SRAKE packages. It includes helpers for creating test databases, fixtures, and mocks.

Index

Constants

This section is empty.

Variables

View Source
var (
	OrganismHuman = "Homo sapiens"
	OrganismMouse = "Mus musculus"
	OrganismYeast = "Saccharomyces cerevisiae"
	OrganismEColi = "Escherichia coli"
	OrganismFly   = "Drosophila melanogaster"
	OrganismWorm  = "Caenorhabditis elegans"
)

Organisms commonly used in tests

View Source
var (
	StrategyRNASeq  = "RNA-Seq"
	StrategyWGS     = "WGS"
	StrategyChIPSeq = "ChIP-Seq"
	StrategyATACSeq = "ATAC-Seq"
	StrategyWXS     = "WXS"
)

Library strategies commonly used in tests

View Source
var (
	PlatformIllumina   = "ILLUMINA"
	PlatformPacBio     = "PACBIO_SMRT"
	PlatformOxford     = "OXFORD_NANOPORE"
	PlatformIONTorrent = "ION_TORRENT"
)

Platforms commonly used in tests

Functions

func AssertContains

func AssertContains(t *testing.T, s, substr, msg string)

AssertContains fails the test if substr is not in s.

func AssertEqual

func AssertEqual[T comparable](t *testing.T, got, want T, msg string)

AssertEqual fails the test if got != want.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse fails the test if condition is true.

func AssertNil

func AssertNil(t *testing.T, value interface{}, msg string)

AssertNil fails the test if value is not nil.

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string)

AssertNoError fails the test if err is not nil.

func AssertNotNil

func AssertNotNil(t *testing.T, value interface{}, msg string)

AssertNotNil fails the test if value is nil.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue fails the test if condition is false.

func ExperimentWithAccession

func ExperimentWithAccession(accession, studyAccession string) *database.Experiment

ExperimentWithAccession returns a test experiment with a specific accession.

func InsertTestExperiments

func InsertTestExperiments(db *database.DB) error

InsertTestExperiments inserts test experiment records.

func InsertTestRuns

func InsertTestRuns(db *database.DB) error

InsertTestRuns inserts test run records.

func InsertTestSamples

func InsertTestSamples(db *database.DB) error

InsertTestSamples inserts test sample records.

func InsertTestStudies

func InsertTestStudies(db *database.DB) error

InsertTestStudies inserts test study records.

func MockContextWithCancel

func MockContextWithCancel() (context.Context, context.CancelFunc)

MockContextWithCancel returns a context with cancel and the cancel function.

func RequireEnv

func RequireEnv(t *testing.T, name string) string

RequireEnv skips the test if the environment variable is not set.

func RequireNoError

func RequireNoError(t *testing.T, err error, msg string)

RequireNoError fails the test immediately if err is not nil.

func RunWithStats

func RunWithStats(accession, expAccession string, spots, bases int64) *database.Run

RunWithStats returns a test run with specific statistics.

func SampleWithOrganism

func SampleWithOrganism(accession, organism string) *database.Sample

SampleWithOrganism returns a test sample with a specific organism.

func SkipIfCI

func SkipIfCI(t *testing.T)

SkipIfCI skips the test if running in CI environment.

func SkipIfShort

func SkipIfShort(t *testing.T, reason string)

SkipIfShort skips the test if running in short mode.

func StudyWithAccession

func StudyWithAccession(accession string) *database.Study

StudyWithAccession returns a test study with a specific accession.

func TempDir

func TempDir(t *testing.T) (string, func())

TempDir creates a temporary directory for tests. It returns the path and a cleanup function.

func TempFile

func TempFile(t *testing.T, name, content string) (string, func())

TempFile creates a temporary file with the given content. It returns the path and a cleanup function.

func TestDB

func TestDB(t *testing.T) (*database.DB, func())

TestDB creates a temporary in-memory database for testing. It returns the database and a cleanup function.

func TestDBWithFixtures

func TestDBWithFixtures(t *testing.T) (*database.DB, func())

TestDBWithFixtures creates a test database and populates it with fixtures.

func TestExperiment

func TestExperiment() *database.Experiment

TestExperiment returns a test experiment with sensible defaults.

func TestRun

func TestRun() *database.Run

TestRun returns a test run with sensible defaults.

func TestSample

func TestSample() *database.Sample

TestSample returns a test sample with sensible defaults.

func TestStudy

func TestStudy() *database.Study

TestStudy returns a test study with sensible defaults.

func TestSubmission

func TestSubmission() *database.Submission

TestSubmission returns a test submission with sensible defaults.

Types

type MockEmbedder

type MockEmbedder struct {

	// Configurable return values
	DefaultEmbedding []float32
	EmbedErr         error
	// contains filtered or unexported fields
}

MockEmbedder is a mock implementation of the embedder interface.

func NewMockEmbedder

func NewMockEmbedder() *MockEmbedder

NewMockEmbedder creates a new mock embedder.

func (*MockEmbedder) Embed

func (m *MockEmbedder) Embed(text string) ([]float32, error)

Embed returns a mock embedding for the given text.

func (*MockEmbedder) EmbedBatch

func (m *MockEmbedder) EmbedBatch(texts []string) ([][]float32, error)

EmbedBatch returns mock embeddings for multiple texts.

func (*MockEmbedder) SetEmbedding

func (m *MockEmbedder) SetEmbedding(text string, embedding []float32)

SetEmbedding sets a specific embedding for a text.

type MockHTTPClient

type MockHTTPClient struct {

	// Default response
	DefaultResponse []byte
	DefaultErr      error
	// contains filtered or unexported fields
}

MockHTTPClient is a mock HTTP client for testing.

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new mock HTTP client.

func (*MockHTTPClient) Get

func (m *MockHTTPClient) Get(url string) ([]byte, error)

Get records a GET request and returns configured response.

func (*MockHTTPClient) Requests

func (m *MockHTTPClient) Requests() []string

Requests returns all recorded requests.

func (*MockHTTPClient) SetError

func (m *MockHTTPClient) SetError(url string, err error)

SetError sets an error for a specific URL.

func (*MockHTTPClient) SetResponse

func (m *MockHTTPClient) SetResponse(url string, response []byte)

SetResponse sets the response for a specific URL.

type MockProgressReporter

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

MockProgressReporter is a mock progress reporter for testing.

func (*MockProgressReporter) Messages

func (m *MockProgressReporter) Messages() []string

Messages returns all recorded messages.

func (*MockProgressReporter) SetMessage

func (m *MockProgressReporter) SetMessage(msg string)

SetMessage records a message update.

func (*MockProgressReporter) Update

func (m *MockProgressReporter) Update(progress int64)

Update records a progress update.

func (*MockProgressReporter) Updates

func (m *MockProgressReporter) Updates() []int64

Updates returns all recorded progress updates.

type MockSearchBackend

type MockSearchBackend struct {

	// Configurable return values
	SearchResult interface{}
	SearchErr    error
	IndexErr     error
	DeleteErr    error
	// contains filtered or unexported fields
}

MockSearchBackend is a mock implementation of the search backend.

func (*MockSearchBackend) Delete

func (m *MockSearchBackend) Delete(id string) error

Delete records a delete operation.

func (*MockSearchBackend) DeletedIDs

func (m *MockSearchBackend) DeletedIDs() []string

DeletedIDs returns all deleted IDs.

func (*MockSearchBackend) Index

func (m *MockSearchBackend) Index(doc interface{}) error

Index records an index operation.

func (*MockSearchBackend) IndexBatch

func (m *MockSearchBackend) IndexBatch(docs []interface{}) error

IndexBatch records a batch index operation.

func (*MockSearchBackend) IndexedDocs

func (m *MockSearchBackend) IndexedDocs() []interface{}

IndexedDocs returns all indexed documents.

func (*MockSearchBackend) Reset

func (m *MockSearchBackend) Reset()

Reset clears all recorded operations.

func (*MockSearchBackend) Search

func (m *MockSearchBackend) Search(query string) (interface{}, error)

Search records a search operation and returns configured results.

func (*MockSearchBackend) SearchQueries

func (m *MockSearchBackend) SearchQueries() []string

SearchQueries returns all search queries.

Jump to

Keyboard shortcuts

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