From 3cc9f5460a808a7a6059a7292806f12e4f414a14 Mon Sep 17 00:00:00 2001 From: heppu Date: Fri, 2 May 2025 09:22:59 +0300 Subject: [PATCH 1/2] Add WithCommandFn --- dep/cmd/cmd.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dep/cmd/cmd.go b/dep/cmd/cmd.go index 2a6072c..9f1c8cd 100644 --- a/dep/cmd/cmd.go +++ b/dep/cmd/cmd.go @@ -96,6 +96,19 @@ func WithCommand(name string, args ...string) Opt { } } +// 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 + } +} + // 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 { From 76645d41ca21419e8292d727d8662d2b8cf38bc1 Mon Sep 17 00:00:00 2001 From: heppu Date: Fri, 2 May 2025 09:24:06 +0300 Subject: [PATCH 2/2] Add access to testcontainer.Container --- dep/container/container.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dep/container/container.go b/dep/container/container.go index 74d83f8..4e134b9 100644 --- a/dep/container/container.go +++ b/dep/container/container.go @@ -1,3 +1,4 @@ +// Package container provides a wrapper around the testcontainers-go library to simplify container management in tests. package container import ( @@ -45,6 +46,12 @@ func (c *Container) Stop() error { return testcontainers.TerminateContainer(c.c) } +// Container returns the underlying testcontainers.Container. +func (c *Container) Container() testcontainers.Container { + return c.c +} + +// 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 @@ -52,6 +59,7 @@ func WithReadyFn(fn func(testcontainers.Container) error) Opt { } } +// 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, @@ -67,6 +75,7 @@ func WithModule[T testcontainers.Container]( } } +// 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)