testx

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 20 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 per enabled database, managing container lifecycle automatically. 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
	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.

type DBSetupFunc

type DBSetupFunc func(ctx context.Context, t *testing.T) *config.DataSourceConfig

DBSetupFunc creates a DataSourceConfig (spinning up a container if needed).

type MinIOContainer

type MinIOContainer struct {
	MinIO *config.MinIOConfig
	// contains filtered or unexported fields
}

func NewMinIOContainer

func NewMinIOContainer(ctx context.Context, t testing.TB) *MinIOContainer

func (*MinIOContainer) Terminate

func (c *MinIOContainer) Terminate(ctx context.Context) error

type MySQLContainer

type MySQLContainer struct {
	DataSource *config.DataSourceConfig
	// contains filtered or unexported fields
}

func NewMySQLContainer

func NewMySQLContainer(ctx context.Context, t testing.TB) *MySQLContainer

func (*MySQLContainer) Terminate

func (c *MySQLContainer) Terminate(ctx context.Context) error

type NamedFactory

type NamedFactory[B any] struct {
	// contains filtered or unexported fields
}

type PostgresContainer

type PostgresContainer struct {
	DataSource *config.DataSourceConfig
	// contains filtered or unexported fields
}

func NewPostgresContainer

func NewPostgresContainer(ctx context.Context, t testing.TB) *PostgresContainer

func (*PostgresContainer) Terminate

func (c *PostgresContainer) Terminate(ctx context.Context) error

type RedisContainer

type RedisContainer struct {
	Redis *config.RedisConfig
	// contains filtered or unexported fields
}

func NewRedisContainer

func NewRedisContainer(ctx context.Context, t testing.TB) *RedisContainer

func (*RedisContainer) Terminate

func (c *RedisContainer) Terminate(ctx context.Context) error

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]) AddNamed

func (r *SuiteRegistry[B]) AddNamed(name string, factory SuiteFactory[B])

AddNamed registers a suite factory with an explicit display name.

func (*SuiteRegistry[B]) Len

func (r *SuiteRegistry[B]) Len() int

Len returns the number of registered suites.

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