diff --git a/framework/components/blockchain/besu.go b/framework/components/blockchain/besu.go index c47b035de..4888f6395 100644 --- a/framework/components/blockchain/besu.go +++ b/framework/components/blockchain/besu.go @@ -67,20 +67,7 @@ func newBesu(in *Input) (*Output, error) { }, Labels: framework.DefaultTCLabels(), HostConfigModifier: func(h *container.HostConfig) { - h.PortBindings = nat.PortMap{ - nat.Port(bindPortWs): []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: bindPortWs, - }, - }, - nat.Port(bindPort): []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: bindPort, - }, - }, - } + h.PortBindings = framework.MapTheSamePort(bindPortWs, bindPort) }, WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond), Cmd: entryPoint, diff --git a/framework/components/blockchain/solana.go b/framework/components/blockchain/solana.go index 91fc6f409..90e79132a 100644 --- a/framework/components/blockchain/solana.go +++ b/framework/components/blockchain/solana.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" - "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" @@ -105,20 +104,7 @@ func newSolana(in *Input) (*Output, error) { WithStartupTimeout(30 * time.Second). WithPollInterval(100 * time.Millisecond), HostConfigModifier: func(h *container.HostConfig) { - h.PortBindings = nat.PortMap{ - nat.Port(bindPort): []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: bindPort, - }, - }, - nat.Port(wsBindPort): []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: wsBindPort, - }, - }, - } + h.PortBindings = framework.MapTheSamePort(bindPort, wsBindPort) h.Mounts = append(h.Mounts, mount.Mount{ Type: mount.TypeBind, Source: contractsDir, diff --git a/framework/components/clnode/clnode.go b/framework/components/clnode/clnode.go index fa429a58a..7e18162f8 100644 --- a/framework/components/clnode/clnode.go +++ b/framework/components/clnode/clnode.go @@ -135,18 +135,17 @@ func generateEntryPoint() []string { func generatePortBindings(in *Input) ([]string, nat.PortMap, error) { httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort) innerDebuggerPort := fmt.Sprintf("%d/tcp", DefaultDebuggerPort) - debuggerPort := fmt.Sprintf("%d/tcp", in.Node.DebuggerPort) portBindings := nat.PortMap{ nat.Port(httpPort): []nat.PortBinding{ { HostIP: "0.0.0.0", - HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort), + HostPort: strconv.Itoa(in.Node.HTTPPort), }, }, nat.Port(innerDebuggerPort): []nat.PortBinding{ { HostIP: "0.0.0.0", - HostPort: debuggerPort, + HostPort: strconv.Itoa(in.Node.DebuggerPort), }, }, } @@ -160,7 +159,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) { customPorts = append(customPorts, fmt.Sprintf("%s/tcp", pp[1])) dockerPort := nat.Port(fmt.Sprintf("%s/tcp", pp[1])) - hostPort := fmt.Sprintf("%s/tcp", pp[0]) + hostPort := pp[0] portBindings[dockerPort] = []nat.PortBinding{ { HostIP: "0.0.0.0", @@ -171,11 +170,10 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) { customPorts = append(customPorts, fmt.Sprintf("%s/tcp", p)) dockerPort := nat.Port(fmt.Sprintf("%s/tcp", p)) - hostPort := fmt.Sprintf("%s/tcp", p) portBindings[dockerPort] = []nat.PortBinding{ { HostIP: "0.0.0.0", - HostPort: hostPort, + HostPort: p, }, } } diff --git a/framework/components/postgres/postgres.go b/framework/components/postgres/postgres.go index 3d44ecf0b..2b10fbb03 100644 --- a/framework/components/postgres/postgres.go +++ b/framework/components/postgres/postgres.go @@ -3,14 +3,16 @@ package postgres import ( "context" "fmt" + "os" + "strconv" + "strings" + "time" + "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/testcontainers/testcontainers-go" tcwait "github.com/testcontainers/testcontainers-go/wait" - "os" - "strings" - "time" ) const ( @@ -121,7 +123,7 @@ func NewPostgreSQL(in *Input) (*Output, error) { nat.Port(bindPort): []nat.PortBinding{ { HostIP: "0.0.0.0", - HostPort: fmt.Sprintf("%d/tcp", portToExpose), + HostPort: strconv.Itoa(portToExpose), }, }, } diff --git a/framework/docker.go b/framework/docker.go index 086a365eb..6fd43faef 100644 --- a/framework/docker.go +++ b/framework/docker.go @@ -47,15 +47,19 @@ func GetHost(container tc.Container) (string, error) { return host, nil } -func MapTheSamePort(port string) nat.PortMap { - return nat.PortMap{ - nat.Port(port): []nat.PortBinding{ +func MapTheSamePort(ports ...string) nat.PortMap { + portMap := nat.PortMap{} + for _, port := range ports { + // need to split off /tcp or /udp + onlyPort := strings.SplitN(port, "/", 2) + portMap[nat.Port(port)] = []nat.PortBinding{ { HostIP: "0.0.0.0", - HostPort: port, + HostPort: onlyPort[0], }, - }, + } } + return portMap } func DefaultTCLabels() map[string]string {