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
25 changes: 2 additions & 23 deletions modules/inbucket/inbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package inbucket
import (
"context"
"fmt"
"net"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
Expand All @@ -19,34 +18,14 @@ type InbucketContainer struct {
//
//nolint:revive,staticcheck //FIXME
func (c *InbucketContainer) SmtpConnection(ctx context.Context) (string, error) {
containerPort, err := c.MappedPort(ctx, "2500/tcp")
if err != nil {
return "", err
}

host, err := c.Host(ctx)
if err != nil {
return "", err
}

return net.JoinHostPort(host, containerPort.Port()), nil
return c.PortEndpoint(ctx, "2500/tcp", "")
}

// WebInterface returns the connection string for the web interface server,
// using the default 9000 port, and obtaining the host and exposed port from
// the container.
func (c *InbucketContainer) WebInterface(ctx context.Context) (string, error) {
containerPort, err := c.MappedPort(ctx, "9000/tcp")
if err != nil {
return "", err
}

host, err := c.Host(ctx)
if err != nil {
return "", err
}

return "http://" + net.JoinHostPort(host, containerPort.Port()), nil
return c.PortEndpoint(ctx, "9000/tcp", "http")
}

// Deprecated: use Run instead
Expand Down
12 changes: 1 addition & 11 deletions modules/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,7 @@ func (c *InfluxDbContainer) MustConnectionUrl(ctx context.Context) string {

//nolint:revive,staticcheck //FIXME
func (c *InfluxDbContainer) ConnectionUrl(ctx context.Context) (string, error) {
containerPort, err := c.MappedPort(ctx, "8086/tcp")
if err != nil {
return "", err
}

host, err := c.Host(ctx)
if err != nil {
return "", err
}

return fmt.Sprintf("http://%s:%s", host, containerPort.Port()), nil
return c.PortEndpoint(ctx, "8086/tcp", "http")
}

func WithUsername(username string) testcontainers.CustomizeRequestOption {
Expand Down
22 changes: 6 additions & 16 deletions modules/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// starterScript {
starterScriptContent = `#!/bin/bash
source /etc/confluent/docker/bash-config
export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://%s:%d,BROKER://%s:9092
export KAFKA_ADVERTISED_LISTENERS=%s,BROKER://%s:9092
echo Starting Kafka KRaft mode
sed -i '/KAFKA_ZOOKEEPER_CONNECT/d' /etc/confluent/docker/configure
echo 'kafka-storage format --ignore-formatted -t "$(kafka-storage random-uuid)" -c /etc/kafka/kafka.properties' >> /etc/confluent/docker/configure
Expand Down Expand Up @@ -128,9 +128,9 @@ func copyStarterScript(ctx context.Context, c testcontainers.Container) error {
return fmt.Errorf("wait for mapped port: %w", err)
}

host, err := c.Host(ctx)
endpoint, err := c.PortEndpoint(ctx, publicPort, "PLAINTEXT")
if err != nil {
return fmt.Errorf("host: %w", err)
return fmt.Errorf("port endpoint: %w", err)
}

inspect, err := c.Inspect(ctx)
Expand All @@ -140,12 +140,7 @@ func copyStarterScript(ctx context.Context, c testcontainers.Container) error {

hostname := inspect.Config.Hostname

port, err := c.MappedPort(ctx, publicPort)
if err != nil {
return fmt.Errorf("mapped port: %w", err)
}

scriptContent := fmt.Sprintf(starterScriptContent, host, port.Int(), hostname)
scriptContent := fmt.Sprintf(starterScriptContent, endpoint, hostname)

if err := c.CopyToContainer(ctx, []byte(scriptContent), starterScript, 0o755); err != nil {
return fmt.Errorf("copy to container: %w", err)
Expand All @@ -165,17 +160,12 @@ func WithClusterID(clusterID string) testcontainers.CustomizeRequestOption {
// Brokers retrieves the broker connection strings from Kafka with only one entry,
// defined by the exposed public port.
func (kc *KafkaContainer) Brokers(ctx context.Context) ([]string, error) {
host, err := kc.Host(ctx)
if err != nil {
return nil, err
}

port, err := kc.MappedPort(ctx, publicPort)
endpoint, err := kc.PortEndpoint(ctx, publicPort, "")
if err != nil {
return nil, err
}

return []string{fmt.Sprintf("%s:%d", host, port.Int())}, nil
return []string{endpoint}, nil
}

// configureControllerQuorumVoters sets the quorum voters for the controller. For that, it will
Expand Down