go-tstr / tstr / dep / container

github.com/go-tstr/tstr/dep/container

pkg.go.dev source
go get github.com/go-tstr/tstr/dep/container@v0.2.1

Overview

Package container provides a wrapper around the testcontainers-go library to simplify container management in tests.

Constants

const (
	ErrCreateWithModule           = strerr.Error("failed to create container with testcontainers module")
	ErrCreateWithGenericContainer = strerr.Error("failed to create generic container")
)

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Opt) *Container

func (*Container) Container

func (c *Container) Container() testcontainers.Container

Container returns the underlying testcontainers.Container.

func (*Container) Ready

func (c *Container) Ready() error

func (*Container) Start

func (c *Container) Start() error

func (*Container) Stop

func (c *Container) Stop() error

type Opt

type Opt func(*Container) error

func WithGenericContainer

func WithGenericContainer(req testcontainers.GenericContainerRequest) Opt

WithGenericContainer creates a container using the testcontainers.GenericContainer function.

func WithModule

func WithModule[T testcontainers.Container](
	runFn func(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (T, error),
	img string,
	opts ...testcontainers.ContainerCustomizer,
) Opt

WithModule creates a container using the testcontainers-go modules.

func WithReadyFn

func WithReadyFn(fn func(testcontainers.Container) error) Opt

WithReadyFn sets a custom readiness function which should block until ready.