Documentation
¶
Overview ¶
Package testkit provides helpers for integration tests powered by Testcontainers.
Index ¶
- Constants
- func RequireDocker(t testing.TB)
- func RequireIntegration(t testing.TB)
- type EMQXContainer
- type EMQXOptions
- type MinIOContainer
- type MinIOOptions
- type PostgresContainer
- type PostgresOptions
- type RedisContainer
- type RedisOptions
- type Suite
- func (s *Suite) Context() context.Context
- func (s *Suite) Endpoint(c testcontainers.Container, scheme string, port string) string
- func (s *Suite) Host(c testcontainers.Container) string
- func (s *Suite) MappedPort(c testcontainers.Container, port string) string
- func (s *Suite) StartContainer(req testcontainers.ContainerRequest) testcontainers.Container
- func (s *Suite) StartEMQX(opts EMQXOptions) *EMQXContainer
- func (s *Suite) StartMinIO(opts MinIOOptions) *MinIOContainer
- func (s *Suite) StartPostgres(opts PostgresOptions) *PostgresContainer
- func (s *Suite) StartRedis(opts RedisOptions) *RedisContainer
Constants ¶
const IntegrationEnv = "RUN_INTEGRATION_TESTS"
IntegrationEnv is an optional environment variable gate for integration tests.
Variables ¶
This section is empty.
Functions ¶
func RequireDocker ¶
RequireDocker skips the test when Docker is unavailable.
func RequireIntegration ¶
RequireIntegration skips the test unless RUN_INTEGRATION_TESTS is set to a truthy value.
Types ¶
type EMQXContainer ¶
type EMQXContainer struct {
Container testcontainers.Container
Host string
DashboardPort string
MQTTPort string
DashboardEndpoint string
Username string
Password string
}
EMQXContainer contains connection details for a started EMQX container.
type EMQXOptions ¶
type EMQXOptions struct {
Image string
Username string
Password string
StartupTimeout time.Duration
}
EMQXOptions controls how the EMQX container is started.
type MinIOContainer ¶
type MinIOContainer struct {
Container testcontainers.Container
Host string
APIPort string
ConsolePort string
Endpoint string
ConsoleEndpoint string
AccessKey string
SecretKey string
}
MinIOContainer contains connection details for a started MinIO container.
func (*MinIOContainer) EndpointURL ¶
func (c *MinIOContainer) EndpointURL() *url.URL
EndpointURL returns the endpoint URL as a parsed value.
func (*MinIOContainer) HostPort ¶
func (c *MinIOContainer) HostPort() string
HostPort returns "host:port" without scheme for S3 clients expecting a custom endpoint resolver.
func (*MinIOContainer) Region ¶
func (c *MinIOContainer) Region() string
Region returns the default MinIO region value when none is explicitly configured.
func (*MinIOContainer) Scheme ¶
func (c *MinIOContainer) Scheme() string
Scheme returns endpoint scheme, defaulting to "http".
type MinIOOptions ¶
type MinIOOptions struct {
Image string
AccessKey string
SecretKey string
StartupTimeout time.Duration
}
MinIOOptions controls how the MinIO container is started.
type PostgresContainer ¶
type PostgresContainer struct {
Container testcontainers.Container
Host string
Port string
Username string
Password string
Database string
}
PostgresContainer contains connection details for a started PostgreSQL container.
func (*PostgresContainer) URL ¶
func (c *PostgresContainer) URL() string
URL returns a postgres:// URL with sslmode disabled, suitable for local integration tests.
type PostgresOptions ¶
type PostgresOptions struct {
Image string
Username string
Password string
Database string
StartupTimeout time.Duration
}
PostgresOptions controls how the PostgreSQL container is started.
type RedisContainer ¶
type RedisContainer struct {
Container testcontainers.Container
Host string
Port string
Password string
}
RedisContainer contains connection details for a started Redis container.
func (*RedisContainer) Addr ¶
func (c *RedisContainer) Addr() string
Addr returns host:port for Redis clients.
type RedisOptions ¶
RedisOptions controls how the Redis container is started.
type Suite ¶
type Suite struct {
// contains filtered or unexported fields
}
Suite is a test helper that owns the context and lifecycle of containers started during a test.
func (*Suite) Endpoint ¶
Endpoint builds a "<scheme>://<host>:<mapped-port>" endpoint for a container port.
func (*Suite) Host ¶
func (s *Suite) Host(c testcontainers.Container) string
Host returns the host where container ports are exposed.
func (*Suite) MappedPort ¶
func (s *Suite) MappedPort(c testcontainers.Container, port string) string
MappedPort returns the mapped host port for a container port.
func (*Suite) StartContainer ¶
func (s *Suite) StartContainer(req testcontainers.ContainerRequest) testcontainers.Container
StartContainer starts a test container and registers automatic cleanup.
func (*Suite) StartEMQX ¶
func (s *Suite) StartEMQX(opts EMQXOptions) *EMQXContainer
StartEMQX starts an EMQX container configured for dashboard API authentication.
func (*Suite) StartMinIO ¶
func (s *Suite) StartMinIO(opts MinIOOptions) *MinIOContainer
StartMinIO starts a MinIO container and returns API and console connection details.
func (*Suite) StartPostgres ¶
func (s *Suite) StartPostgres(opts PostgresOptions) *PostgresContainer
StartPostgres starts a PostgreSQL container and returns its connection details.
func (*Suite) StartRedis ¶
func (s *Suite) StartRedis(opts RedisOptions) *RedisContainer
StartRedis starts a Redis container and returns its connection details.