Skip to content

Commit c56c5ed

Browse files
authored
Merge pull request #45 from go-tstr/dep-improvements
Dep improvements
2 parents 450eadf + 76645d4 commit c56c5ed

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

dep/cmd/cmd.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ func WithCommand(name string, args ...string) Opt {
9696
}
9797
}
9898

99+
// WithCommandFn creates a new command using the given function.
100+
// This is useful for lazy loading of the command and using arguments from other dependencies.
101+
func WithCommandFn(fn func() (*exec.Cmd, error)) Opt {
102+
return func(c *Cmd) error {
103+
cmd, err := fn()
104+
if err != nil {
105+
return err
106+
}
107+
c.cmd = cmd
108+
return nil
109+
}
110+
}
111+
99112
// WithReadyFn allows user to provide custom readiness function.
100113
// Given fn should block until the command is ready.
101114
func WithReadyFn(fn func(*exec.Cmd) error) Opt {

dep/container/container.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package container provides a wrapper around the testcontainers-go library to simplify container management in tests.
12
package container
23

34
import (
@@ -45,13 +46,20 @@ func (c *Container) Stop() error {
4546
return testcontainers.TerminateContainer(c.c)
4647
}
4748

49+
// Container returns the underlying testcontainers.Container.
50+
func (c *Container) Container() testcontainers.Container {
51+
return c.c
52+
}
53+
54+
// WithReadyFn sets a custom readiness function which should block until ready.
4855
func WithReadyFn(fn func(testcontainers.Container) error) Opt {
4956
return func(c *Container) error {
5057
c.ready = fn
5158
return nil
5259
}
5360
}
5461

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

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

0 commit comments

Comments
 (0)