Skip to content
Merged
24 changes: 13 additions & 11 deletions modules/azure/eventhubs/eventhubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,7 @@ func (c *Container) Terminate(ctx context.Context, opts ...testcontainers.Termin

// Run creates an instance of the Azure Event Hubs container type
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) {
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultAMPQPort, defaultHTTPPort),
testcontainers.WithWaitStrategy(wait.ForAll(
wait.ForListeningPort(defaultAMPQPort),
wait.ForListeningPort(defaultHTTPPort),
wait.ForHTTP("/health").WithPort(defaultHTTPPort).WithStatusCodeMatcher(func(status int) bool {
return status == http.StatusOK
}),
)),
}

// Process custom options first to extract settings
defaultOptions := defaultOptions()
for _, opt := range opts {
if o, ok := opt.(Option); ok {
Expand All @@ -90,6 +80,18 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom

c := &Container{azuriteOptions: &defaultOptions}

// Build moduleOpts with defaults
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultAMPQPort, defaultHTTPPort),
testcontainers.WithWaitStrategy(wait.ForAll(
wait.ForListeningPort(defaultAMPQPort),
wait.ForListeningPort(defaultHTTPPort),
wait.ForHTTP("/health").WithPort(defaultHTTPPort).WithStatusCodeMatcher(func(status int) bool {
return status == http.StatusOK
}),
)),
}

if defaultOptions.azuriteContainer == nil {
azuriteNetwork, err := network.New(ctx)
if err != nil {
Expand Down
24 changes: 13 additions & 11 deletions modules/azure/servicebus/servicebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ func (c *Container) Terminate(ctx context.Context, opts ...testcontainers.Termin

// Run creates an instance of the Azure ServiceBus container type
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) {
// Process custom options first to extract settings
defaultOptions := defaultOptions()
for _, opt := range opts {
if o, ok := opt.(Option); ok {
if err := o(&defaultOptions); err != nil {
return nil, fmt.Errorf("servicebus option: %w", err)
}
}
}

c := &Container{mssqlOptions: &defaultOptions}

// Build moduleOpts with defaults
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultPort, defaultHTTPPort),
testcontainers.WithEnv(map[string]string{
Expand All @@ -87,17 +100,6 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
)),
}

defaultOptions := defaultOptions()
for _, opt := range opts {
if o, ok := opt.(Option); ok {
if err := o(&defaultOptions); err != nil {
return nil, fmt.Errorf("servicebus option: %w", err)
}
}
}

c := &Container{mssqlOptions: &defaultOptions}

if defaultOptions.mssqlContainer == nil {
mssqlNetwork, err := network.New(ctx)
if err != nil {
Expand Down
25 changes: 14 additions & 11 deletions modules/couchbase/couchbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
indexStorageMode: MemoryOptimized,
}

moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(MGMT_PORT+"/tcp", MGMT_SSL_PORT+"/tcp"),
}

serviceCustomizers := make([]testcontainers.ContainerCustomizer, 0, len(initialServices))
// Process custom options first to extract config
// Start with initial services
allCustomizers := make([]testcontainers.ContainerCustomizer, 0, len(initialServices)+len(opts))
for _, srv := range initialServices {
serviceCustomizers = append(serviceCustomizers, withService(srv))
allCustomizers = append(allCustomizers, withService(srv))
}
allCustomizers = append(allCustomizers, opts...)

serviceCustomizers = append(serviceCustomizers, opts...)

// transfer options to the config
for _, opt := range serviceCustomizers {
// Transfer custom options to the config
for _, opt := range allCustomizers {
if bucketCustomizer, ok := opt.(bucketCustomizer); ok {
// If the option is a bucketCustomizer, we need to add the buckets to the request
config.buckets = append(config.buckets, bucketCustomizer.buckets...)
Expand All @@ -105,7 +102,13 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
}
}

moduleOpts = append(moduleOpts, serviceCustomizers...)
// Build moduleOpts with defaults
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(MGMT_PORT+"/tcp", MGMT_SSL_PORT+"/tcp"),
}

// Append all customizers (initial services + user opts)
moduleOpts = append(moduleOpts, allCustomizers...)

ctr, err := testcontainers.Run(ctx, img, moduleOpts...)
var couchbaseContainer *CouchbaseContainer
Expand Down
31 changes: 17 additions & 14 deletions modules/dockermcpgateway/dockermcpgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@ type Container struct {
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) {
dockerHostMount := core.MustExtractDockerSocket(ctx)

moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultPort),
testcontainers.WithHostConfigModifier(func(hc *container.HostConfig) {
hc.Binds = []string{
dockerHostMount + ":/var/run/docker.sock",
}
}),
testcontainers.WithWaitStrategy(wait.ForAll(
wait.ForListeningPort(defaultPort),
wait.ForLog(".*Start sse server on port.*").AsRegexp(),
)),
}

// Process custom options first to extract settings
settings := defaultOptions()
for _, opt := range opts {
if apply, ok := opt.(Option); ok {
Expand All @@ -56,6 +44,21 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
cmds = append(cmds, "--tools="+tool)
}
}

// Build moduleOpts with defaults
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultPort),
testcontainers.WithHostConfigModifier(func(hc *container.HostConfig) {
hc.Binds = []string{
dockerHostMount + ":/var/run/docker.sock",
}
}),
testcontainers.WithWaitStrategy(wait.ForAll(
wait.ForListeningPort(defaultPort),
wait.ForLog(".*Start sse server on port.*").AsRegexp(),
)),
}

if len(settings.secrets) > 0 {
cmds = append(cmds, "--secrets="+secretsPath)

Expand All @@ -73,7 +76,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom

moduleOpts = append(moduleOpts, testcontainers.WithCmd(cmds...))

// append user-defined options
// Append user options
moduleOpts = append(moduleOpts, opts...)

container, err := testcontainers.Run(ctx, img, moduleOpts...)
Expand Down
15 changes: 9 additions & 6 deletions modules/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ func (c *EtcdContainer) Terminate(ctx context.Context, opts ...testcontainers.Te

// Run creates an instance of the etcd container type
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*EtcdContainer, error) {
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(clientPort, peerPort),
}

moduleOpts = append(moduleOpts, opts...)

// Process custom options first to extract settings
settings := defaultOptions()
for _, opt := range opts {
if apply, ok := opt.(Option); ok {
Expand All @@ -80,6 +75,14 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
return nil, fmt.Errorf("configure cluster: %w", err)
}

// Build moduleOpts with defaults
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(clientPort, peerPort),
}

// Append user options
moduleOpts = append(moduleOpts, opts...)

// configure CMD with the nodes
moduleOpts = append(moduleOpts, testcontainers.WithCmd(configureCMD(settings)...))

Expand Down
28 changes: 15 additions & 13 deletions modules/gcloud/firestore/firestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ func (c *Container) URI() string {
// Run creates an instance of the Firestore GCloud container type.
// The URI uses the empty string as the protocol.
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) {
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultPort),
testcontainers.WithWaitStrategy(wait.ForAll(
wait.ForListeningPort(defaultPort),
wait.ForLog("running"),
)),
}

// Process custom options first to extract settings
settings := defaultOptions()
for _, opt := range opts {
if apply, ok := opt.(Option); ok {
Expand All @@ -56,12 +49,21 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
gcloudParameters += " --database-mode=datastore-mode"
}

moduleOpts = append(moduleOpts, testcontainers.WithCmd(
"/bin/sh",
"-c",
"gcloud beta emulators firestore start --host-port 0.0.0.0:"+defaultPortNumber+" "+gcloudParameters,
))
// Build moduleOpts with defaults
moduleOpts := []testcontainers.ContainerCustomizer{
testcontainers.WithExposedPorts(defaultPort),
testcontainers.WithWaitStrategy(wait.ForAll(
wait.ForListeningPort(defaultPort),
wait.ForLog("running"),
)),
testcontainers.WithCmd(
"/bin/sh",
"-c",
"gcloud beta emulators firestore start --host-port 0.0.0.0:"+defaultPortNumber+" "+gcloudParameters,
),
}

// Append user options
moduleOpts = append(moduleOpts, opts...)

ctr, err := testcontainers.Run(ctx, img, moduleOpts...)
Expand Down
Loading