@@ -72,17 +72,17 @@ func (c *Container) resolveURL(ctx context.Context, port nat.Port) (string, erro
7272// and add a waiting strategy for the functions worker
7373func WithFunctionsWorker () testcontainers.CustomizeRequestOption {
7474 return func (req * testcontainers.GenericContainerRequest ) error {
75- req .Cmd = []string {"/bin/bash" , "-c" , defaultPulsarCmd }
75+ if err := testcontainers .WithCmd ("/bin/bash" , "-c" , defaultPulsarCmd )(req ); err != nil {
76+ return err
77+ }
7678
7779 ss := []wait.Strategy {
7880 wait .ForLog ("Function worker service started" ),
7981 }
8082
8183 ss = append (ss , defaultWaitStrategies .Strategies ... )
8284
83- req .WaitingFor = wait .ForAll (ss ... )
84-
85- return nil
85+ return testcontainers .WithWaitStrategy (wait .ForAll (ss ... ))(req )
8686 }
8787}
8888
@@ -103,9 +103,7 @@ func (c *Container) WithLogConsumers(ctx context.Context, _ ...testcontainers.Lo
103103// WithPulsarEnv allows to use the native APIs and set each variable with PULSAR_PREFIX_ as prefix.
104104func WithPulsarEnv (configVar string , configValue string ) testcontainers.CustomizeRequestOption {
105105 return func (req * testcontainers.GenericContainerRequest ) error {
106- req .Env ["PULSAR_PREFIX_" + configVar ] = configValue
107-
108- return nil
106+ return testcontainers .WithEnv (map [string ]string {"PULSAR_PREFIX_" + configVar : configValue })(req )
109107 }
110108}
111109
@@ -124,9 +122,7 @@ func WithTransactions() testcontainers.CustomizeRequestOption {
124122
125123 ss = append (ss , defaultWaitStrategies .Strategies ... )
126124
127- req .WaitingFor = wait .ForAll (ss ... )
128-
129- return nil
125+ return testcontainers .WithWaitStrategy (wait .ForAll (ss ... ))(req )
130126 }
131127}
132128
@@ -146,33 +142,22 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
146142//
147143// - command: "/bin/bash -c /pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone --no-functions-worker -nss"
148144func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* Container , error ) {
149- req := testcontainers.ContainerRequest {
150- Image : img ,
151- Env : map [string ]string {},
152- ExposedPorts : []string {defaultPulsarPort , defaultPulsarAdminPort },
153- WaitingFor : defaultWaitStrategies ,
154- Cmd : []string {"/bin/bash" , "-c" , strings .Join ([]string {defaultPulsarCmd , defaultPulsarCmdWithoutFunctionsWorker }, " " )},
145+ moduleOpts := []testcontainers.ContainerCustomizer {
146+ testcontainers .WithExposedPorts (defaultPulsarPort , defaultPulsarAdminPort ),
147+ testcontainers .WithWaitStrategy (defaultWaitStrategies ),
148+ testcontainers .WithCmd ("/bin/bash" , "-c" , strings .Join ([]string {defaultPulsarCmd , defaultPulsarCmdWithoutFunctionsWorker }, " " )),
155149 }
156150
157- genericContainerReq := testcontainers.GenericContainerRequest {
158- ContainerRequest : req ,
159- Started : true ,
160- }
161-
162- for _ , opt := range opts {
163- if err := opt .Customize (& genericContainerReq ); err != nil {
164- return nil , err
165- }
166- }
151+ moduleOpts = append (moduleOpts , opts ... )
167152
168- container , err := testcontainers .GenericContainer (ctx , genericContainerReq )
153+ ctr , err := testcontainers .Run (ctx , img , moduleOpts ... )
169154 var c * Container
170- if container != nil {
171- c = & Container {Container : container }
155+ if ctr != nil {
156+ c = & Container {Container : ctr }
172157 }
173158
174159 if err != nil {
175- return c , fmt .Errorf ("generic container : %w" , err )
160+ return c , fmt .Errorf ("run pulsar : %w" , err )
176161 }
177162
178163 return c , nil
0 commit comments