Documentation
¶
Index ¶
Constants ¶
const ( PostgresImage = "postgres:18-alpine" MySQLImage = "mysql:lts" RedisImage = "redis:8-alpine" MinIOImage = "minio/minio:latest" )
Container images.
const ( TestDatabaseName = "testdb" TestUsername = "testuser" TestPassword = "testpass" )
Database credentials.
const ( TestMinIOAccessKey = "testadmin" TestMinIOSecretKey = "testadmin" TestMinIOBucket = "testbucket" )
MinIO credentials.
const DefaultContainerTimeout = 30 * time.Second
DefaultContainerTimeout is the maximum wait time for container readiness.
Variables ¶
This section is empty.
Functions ¶
func ForEachDB ¶
ForEachDB runs fn once for each supported database (Postgres, MySQL, SQLite), managing container lifecycle automatically. Postgres and MySQL require Docker; the suite hard-fails at container start if Docker is unavailable. SQLite uses a temp-dir file and needs no container. Test hierarchy: t.Run("<DisplayName>", fn).
Types ¶
type DBEnv ¶
type DBEnv struct {
T *testing.T
Ctx context.Context //nolint:containedctx // test-only ergonomic exception; see type doc
RawDB *sql.DB
BunDB *bun.DB
DB orm.DB
DS *config.DataSourceConfig
}
DBEnv encapsulates the database environment for cross-database integration tests. Contains both the raw sql.DB connection and a wrapped orm.DB for convenience.
Ctx is a deliberate test-only exception to the "don't store context on a struct" guideline: it is set to context.Background() by ForEachDB so suites that receive a *DBEnv can pass a ready-to-use context without threading one through every call. Production code must never follow this pattern.
type MinIOContainer ¶
type MinIOContainer struct {
MinIO *config.MinIOConfig
// contains filtered or unexported fields
}
func NewMinIOContainer ¶
func NewMinIOContainer(ctx context.Context, t testing.TB) *MinIOContainer
type MySQLContainer ¶
type MySQLContainer struct {
DataSource *config.DataSourceConfig
// contains filtered or unexported fields
}
func NewMySQLContainer ¶
func NewMySQLContainer(ctx context.Context, t testing.TB) *MySQLContainer
type PostgresContainer ¶
type PostgresContainer struct {
DataSource *config.DataSourceConfig
// contains filtered or unexported fields
}
func NewPostgresContainer ¶
func NewPostgresContainer(ctx context.Context, t testing.TB) *PostgresContainer
type RedisContainer ¶
type RedisContainer struct {
Redis *config.RedisConfig
// contains filtered or unexported fields
}
func NewRedisContainer ¶
func NewRedisContainer(ctx context.Context, t testing.TB) *RedisContainer
type SuiteFactory ¶
type SuiteFactory[B any] func(base *B) suite.TestingSuite
SuiteFactory creates a testify suite instance from a shared base configuration.
type SuiteRegistry ¶
type SuiteRegistry[B any] struct { // contains filtered or unexported fields }
SuiteRegistry holds suite factories and orchestrates their execution across databases.
func NewRegistry ¶
func NewRegistry[B any]() *SuiteRegistry[B]
NewRegistry creates a new empty suite registry.
func (*SuiteRegistry[B]) Add ¶
func (r *SuiteRegistry[B]) Add(factory SuiteFactory[B])
Add registers a suite factory. The test name is auto-extracted from the concrete suite type name, with "TestSuite" suffix stripped for cleaner test output.