testx

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostgresImage = "postgres:18-alpine"
	MySQLImage    = "mysql:lts"
	RedisImage    = "redis:8-alpine"
	MinIOImage    = "minio/minio:latest"
)

Container images.

View Source
const (
	TestDatabaseName = "testdb"
	TestUsername     = "testuser"
	TestPassword     = "testpass"
)

Database credentials.

View Source
const (
	TestMinIOAccessKey = "testadmin"
	TestMinIOSecretKey = "testadmin"
	TestMinIOBucket    = "testbucket"
)

MinIO credentials.

View Source
const DefaultContainerTimeout = 30 * time.Second

DefaultContainerTimeout is the maximum wait time for container readiness.

Variables

This section is empty.

Functions

func ForEachDB

func ForEachDB(t *testing.T, fn func(t *testing.T, env *DBEnv))

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).

func NewTestDB

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

NewTestDB creates a lightweight SQLite in-memory orm.DB for unit tests. The database connection is automatically closed via t.Cleanup.

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.

func (*SuiteRegistry[B]) RunAll

func (r *SuiteRegistry[B]) RunAll(t *testing.T, baseFactory func(env *DBEnv) *B)

RunAll iterates all databases, creates a base via baseFactory for each, then runs every registered suite. Test hierarchy: TestAll/<DBDisplayName>/<SuiteName>/...

Jump to

Keyboard shortcuts

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