Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dep/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@
}
}

// WithCommandFn creates a new command using the given function.
// This is useful for lazy loading of the command and using arguments from other dependencies.
func WithCommandFn(fn func() (*exec.Cmd, error)) Opt {
return func(c *Cmd) error {
cmd, err := fn()
if err != nil {
return err
}
c.cmd = cmd
return nil

Check warning on line 108 in dep/cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

dep/cmd/cmd.go#L101-L108

Added lines #L101 - L108 were not covered by tests
}
}

// WithReadyFn allows user to provide custom readiness function.
// Given fn should block until the command is ready.
func WithReadyFn(fn func(*exec.Cmd) error) Opt {
Expand Down
9 changes: 9 additions & 0 deletions dep/container/container.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package container provides a wrapper around the testcontainers-go library to simplify container management in tests.
package container

import (
Expand Down Expand Up @@ -45,13 +46,20 @@
return testcontainers.TerminateContainer(c.c)
}

// Container returns the underlying testcontainers.Container.
func (c *Container) Container() testcontainers.Container {
return c.c

Check warning on line 51 in dep/container/container.go

View check run for this annotation

Codecov / codecov/patch

dep/container/container.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}

// WithReadyFn sets a custom readiness function which should block until ready.
func WithReadyFn(fn func(testcontainers.Container) error) Opt {
return func(c *Container) error {
c.ready = fn
return nil
}
}

// WithModule creates a container using the testcontainers-go modules.
func WithModule[T testcontainers.Container](
runFn func(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (T, error),
img string,
Expand All @@ -67,6 +75,7 @@
}
}

// WithGenericContainer creates a container using the testcontainers.GenericContainer function.
func WithGenericContainer(req testcontainers.GenericContainerRequest) Opt {
return func(c *Container) (err error) {
c.c, err = testcontainers.GenericContainer(context.Background(), req)
Expand Down