Documentation
¶
Overview ¶
Package testutil provides testing utilities for SRAKE packages. It includes helpers for creating test databases, fixtures, and mocks.
Index ¶
- Variables
- func AssertContains(t *testing.T, s, substr, msg string)
- func AssertEqual[T comparable](t *testing.T, got, want T, msg string)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertNil(t *testing.T, value interface{}, msg string)
- func AssertNoError(t *testing.T, err error, msg string)
- func AssertNotNil(t *testing.T, value interface{}, msg string)
- func AssertTrue(t *testing.T, condition bool, msg string)
- func ExperimentWithAccession(accession, studyAccession string) *database.Experiment
- func InsertTestExperiments(db *database.DB) error
- func InsertTestRuns(db *database.DB) error
- func InsertTestSamples(db *database.DB) error
- func InsertTestStudies(db *database.DB) error
- func MockContextWithCancel() (context.Context, context.CancelFunc)
- func RequireEnv(t *testing.T, name string) string
- func RequireNoError(t *testing.T, err error, msg string)
- func RunWithStats(accession, expAccession string, spots, bases int64) *database.Run
- func SampleWithOrganism(accession, organism string) *database.Sample
- func SkipIfCI(t *testing.T)
- func SkipIfShort(t *testing.T, reason string)
- func StudyWithAccession(accession string) *database.Study
- func TempDir(t *testing.T) (string, func())
- func TempFile(t *testing.T, name, content string) (string, func())
- func TestDB(t *testing.T) (*database.DB, func())
- func TestDBWithFixtures(t *testing.T) (*database.DB, func())
- func TestExperiment() *database.Experiment
- func TestRun() *database.Run
- func TestSample() *database.Sample
- func TestStudy() *database.Study
- func TestSubmission() *database.Submission
- type MockEmbedder
- type MockHTTPClient
- type MockProgressReporter
- type MockSearchBackend
- func (m *MockSearchBackend) Delete(id string) error
- func (m *MockSearchBackend) DeletedIDs() []string
- func (m *MockSearchBackend) Index(doc interface{}) error
- func (m *MockSearchBackend) IndexBatch(docs []interface{}) error
- func (m *MockSearchBackend) IndexedDocs() []interface{}
- func (m *MockSearchBackend) Reset()
- func (m *MockSearchBackend) Search(query string) (interface{}, error)
- func (m *MockSearchBackend) SearchQueries() []string
Constants ¶
This section is empty.
Variables ¶
var ( OrganismHuman = "Homo sapiens" OrganismMouse = "Mus musculus" OrganismYeast = "Saccharomyces cerevisiae" OrganismEColi = "Escherichia coli" OrganismFly = "Drosophila melanogaster" OrganismWorm = "Caenorhabditis elegans" )
Organisms commonly used in tests
var ( StrategyRNASeq = "RNA-Seq" StrategyWGS = "WGS" StrategyChIPSeq = "ChIP-Seq" StrategyATACSeq = "ATAC-Seq" StrategyWXS = "WXS" )
Library strategies commonly used in tests
var ( PlatformIllumina = "ILLUMINA" PlatformPacBio = "PACBIO_SMRT" PlatformOxford = "OXFORD_NANOPORE" PlatformIONTorrent = "ION_TORRENT" )
Platforms commonly used in tests
Functions ¶
func AssertContains ¶
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 ¶
AssertFalse fails the test if condition is true.
func AssertNoError ¶
AssertNoError fails the test if err is not nil.
func AssertNotNil ¶
AssertNotNil fails the test if value is nil.
func AssertTrue ¶
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 ¶
InsertTestExperiments inserts test experiment records.
func InsertTestRuns ¶
InsertTestRuns inserts test run records.
func InsertTestSamples ¶
InsertTestSamples inserts test sample records.
func InsertTestStudies ¶
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 ¶
RequireEnv skips the test if the environment variable is not set.
func RequireNoError ¶
RequireNoError fails the test immediately if err is not nil.
func RunWithStats ¶
RunWithStats returns a test run with specific statistics.
func SampleWithOrganism ¶
SampleWithOrganism returns a test sample with a specific organism.
func SkipIfShort ¶
SkipIfShort skips the test if running in short mode.
func StudyWithAccession ¶
StudyWithAccession returns a test study with a specific accession.
func TempDir ¶
TempDir creates a temporary directory for tests. It returns the path and a cleanup function.
func TempFile ¶
TempFile creates a temporary file with the given content. It returns the path and a cleanup function.
func TestDB ¶
TestDB creates a temporary in-memory database for testing. It returns the database and a cleanup function.
func TestDBWithFixtures ¶
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 TestSample ¶
TestSample returns a test sample 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.