stdtestcontainer

package
v0.0.262 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stdtestcontainer provides re-usable code for using testcontainer-go.

Index

Constants

View Source
const (
	S3AccessKey = "stdgo"
	S3SecretKey = "stdgo-secret"
)

Credentials of the root user of every S3 server started here; not a secret.

View Source
const PostgresMaxConnections = 2000

PostgresMaxConnections is the max_connections of the server that Postgres starts. It leaves room for test packages that run in parallel, each with parallel tests whose pools stdpgxfx.TestProvide caps (STDPGX_POOL_MAX_CONNS). It is one value for the whole run, because every test package shares the server, and the first to start it sets its flags.

Variables

View Source
var (
	// CreateGenericContainer sets the function used for creating the generic container, can be replaced for testing.
	CreateGenericContainer = testcontainers.GenericContainer
	// CleanupContainer sets the function used for cleaning up the container, can be replaced for testing.
	CleanupContainer = testcontainers.CleanupContainer
)

Functions

func Postgres added in v0.0.244

func Postgres(tb testing.TB, image string) string

Postgres returns the connection URL of a PostgreSQL server that is shared by every test, and every test package, of the same `go test` run. The first call starts the server in a container; later calls, including those from other test packages (which Go runs in other processes), reuse it. Testcontainers' reaper (Ryuk) removes the container after the run, so tests never stop it themselves.

The image, e.g. "postgres:18", is required so the server matches the version the code runs against in production; callers asking for different images get different servers.

The server holds no data that tests can rely on: create a separate database per test on top of it, e.g. with pgtestdb or stdpgxtestfx. It requires a running Docker daemon.

func S3 added in v0.0.255

func S3(tb testing.TB, image string) string

S3 returns the endpoint URL of an S3-compatible server that is shared by every test, and every test package, of the same `go test` run. Sign requests with S3AccessKey and S3SecretKey. The first call starts the server in a container; later calls, including those from other test packages (which Go runs in other processes), reuse it. Testcontainers' reaper (Ryuk) removes the container after the run, so tests never stop it themselves.

The image is required so the server matches the one the code runs against elsewhere, such as in Docker Compose; callers asking for different images get different servers. The image must take MinIO's "server" command and MINIO_ROOT_USER and MINIO_ROOT_PASSWORD variables, as MinIO's own images and forks such as pgsty/silo do.

The server holds no data that tests can rely on: create separate buckets per test on top of it, e.g. with stds3testfx. It requires a running Docker daemon.

func SetupLambdaRIEContainer

func SetupLambdaRIEContainer(
	t *testing.T,
	ctx context.Context,
	imageName string,
	entrypoint []string,
	platform string,
	env map[string]string,
	hostRieFilePath string,
	hostAWSCredentialsFilePath string,
) *requests.Builder

SetupLambdaRIEContainer will use testcontainers-go to setup a container for e2e testing of a lambda handler.

Types

This section is empty.

Jump to

Keyboard shortcuts

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