Documentation
¶
Overview ¶
Package hesper provides a Go library for managing Apple Containers in tests.
Index ¶
- Variables
- type Config
- type Container
- type HesperError
- type NoWait
- type Option
- func WithAutoRemove() Option
- func WithCommand(command ...string) Option
- func WithEntrypoint(entrypoint ...string) Option
- func WithEnv(key, value string) Option
- func WithLabel(key, value string) Option
- func WithName(name string) Option
- func WithPort(hostPort, containerPort int) Option
- func WithVolume(hostPath, containerPath string, readonly bool) Option
- func WithWaitStrategy(strategy WaitStrategy) Option
- func WithWorkDir(workDir string) Option
- type RunInput
- type WaitForAll
- type WaitForExec
- type WaitForLog
- type WaitForPort
- type WaitStrategy
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is exported to allow external packages to implement Option.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container represents a running container managed by Hesper.
func MustRun ¶
MustRun is a convenience wrapper around Run that panics on error. This is useful for test setup code where you want to fail fast.
Example:
container := hesper.MustRun(ctx, "postgres:16-alpine",
hesper.WithEnv("POSTGRES_PASSWORD", "secret"),
)
defer container.Stop(ctx)
func Run ¶
Run starts a new container with the specified image and options. It automatically adds the hesper.managed=true label for cleanup tracking.
The Run function performs these operations in order:
- Cleans up any orphaned containers from previous runs (once per process)
- Applies all provided options to configure the container
- Starts the container using the container CLI
- Inspects the container to retrieve published port mappings
- Waits for the container to be ready (if a wait strategy is provided)
- Returns a *Container with the container ID and published ports
Use WithPort to publish container ports to the host. Use Container.Host to get the host address for a published port.
Example:
ctx := context.Background()
container, err := hesper.Run(ctx, "postgres:16-alpine",
hesper.WithEnv("POSTGRES_PASSWORD", "secret"),
hesper.WithPort(15432, 5432),
hesper.WithWaitStrategy(hesper.NewWaitForLog("ready to accept connections")),
)
if err != nil {
log.Fatal(err)
}
defer container.Stop(ctx)
func RunWithInput ¶
RunWithInput is an alternative to Run that uses a struct for parameters. This is useful when you need to pass many options or want to build the configuration programmatically.
type HesperError ¶
func (*HesperError) Error ¶
func (e *HesperError) Error() string
func (*HesperError) Unwrap ¶
func (e *HesperError) Unwrap() error
type Option ¶
Option configures a container.
func WithAutoRemove ¶
func WithAutoRemove() Option
func WithCommand ¶
func WithEntrypoint ¶
func WithVolume ¶
func WithWaitStrategy ¶
func WithWaitStrategy(strategy WaitStrategy) Option
func WithWorkDir ¶
type WaitForAll ¶
type WaitForAll struct {
// contains filtered or unexported fields
}
WaitForAll combines multiple wait strategies, running them in sequence.
func NewWaitForAll ¶
func NewWaitForAll(strategies ...WaitStrategy) *WaitForAll
func (*WaitForAll) WaitUntilReady ¶
func (w *WaitForAll) WaitUntilReady(ctx context.Context, container *Container) error
type WaitForExec ¶
type WaitForExec struct {
// contains filtered or unexported fields
}
WaitForExec waits until a command executed inside the container exits successfully.
func NewWaitForExec ¶
func NewWaitForExec(command ...string) *WaitForExec
func (*WaitForExec) WaitUntilReady ¶
func (w *WaitForExec) WaitUntilReady(ctx context.Context, container *Container) error
type WaitForLog ¶
type WaitForLog struct {
// contains filtered or unexported fields
}
func NewWaitForLog ¶
func NewWaitForLog(message string) *WaitForLog
func WaitForLogOccurrence ¶
func WaitForLogOccurrence(message string, count int) *WaitForLog
func (*WaitForLog) WaitUntilReady ¶
func (w *WaitForLog) WaitUntilReady(ctx context.Context, container *Container) error
func (*WaitForLog) WithPollInterval ¶
func (w *WaitForLog) WithPollInterval(interval time.Duration) *WaitForLog
type WaitForPort ¶
type WaitForPort struct {
// contains filtered or unexported fields
}
WaitForPort waits until a published container port accepts TCP connections.
func NewWaitForPort ¶
func NewWaitForPort(containerPort int) *WaitForPort
func (*WaitForPort) WaitUntilReady ¶
func (w *WaitForPort) WaitUntilReady(ctx context.Context, container *Container) error
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
exec
Package exec provides internal utilities for executing container CLI commands.
|
Package exec provides internal utilities for executing container CLI commands. |
|
reaper
Package reaper provides functionality to clean up orphaned containers.
|
Package reaper provides functionality to clean up orphaned containers. |
|
modules
|
|
|
postgres
Package postgres provides a Postgres-specific wrapper around the hesper container library.
|
Package postgres provides a Postgres-specific wrapper around the hesper container library. |