Skip to content

Commit 3e4d216

Browse files
committed
Fix host port binding syntax
1 parent d70db91 commit 3e4d216

File tree

5 files changed

+17
-40
lines changed

5 files changed

+17
-40
lines changed

framework/components/blockchain/besu.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,7 @@ func newBesu(in *Input) (*Output, error) {
6767
},
6868
Labels: framework.DefaultTCLabels(),
6969
HostConfigModifier: func(h *container.HostConfig) {
70-
h.PortBindings = nat.PortMap{
71-
nat.Port(bindPortWs): []nat.PortBinding{
72-
{
73-
HostIP: "0.0.0.0",
74-
HostPort: bindPortWs,
75-
},
76-
},
77-
nat.Port(bindPort): []nat.PortBinding{
78-
{
79-
HostIP: "0.0.0.0",
80-
HostPort: bindPort,
81-
},
82-
},
83-
}
70+
h.PortBindings = framework.MapTheSamePort(bindPortWs, bindPort)
8471
},
8572
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
8673
Cmd: entryPoint,

framework/components/blockchain/solana.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/docker/docker/api/types/container"
1313
"github.com/docker/docker/api/types/mount"
14-
"github.com/docker/go-connections/nat"
1514
"github.com/testcontainers/testcontainers-go"
1615
"github.com/testcontainers/testcontainers-go/wait"
1716

@@ -105,20 +104,7 @@ func newSolana(in *Input) (*Output, error) {
105104
WithStartupTimeout(30 * time.Second).
106105
WithPollInterval(100 * time.Millisecond),
107106
HostConfigModifier: func(h *container.HostConfig) {
108-
h.PortBindings = nat.PortMap{
109-
nat.Port(bindPort): []nat.PortBinding{
110-
{
111-
HostIP: "0.0.0.0",
112-
HostPort: bindPort,
113-
},
114-
},
115-
nat.Port(wsBindPort): []nat.PortBinding{
116-
{
117-
HostIP: "0.0.0.0",
118-
HostPort: wsBindPort,
119-
},
120-
},
121-
}
107+
h.PortBindings = framework.MapTheSamePort(bindPort, wsBindPort)
122108
h.Mounts = append(h.Mounts, mount.Mount{
123109
Type: mount.TypeBind,
124110
Source: contractsDir,

framework/components/clnode/clnode.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,17 @@ func generateEntryPoint() []string {
135135
func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
136136
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
137137
innerDebuggerPort := fmt.Sprintf("%d/tcp", DefaultDebuggerPort)
138-
debuggerPort := fmt.Sprintf("%d/tcp", in.Node.DebuggerPort)
139138
portBindings := nat.PortMap{
140139
nat.Port(httpPort): []nat.PortBinding{
141140
{
142141
HostIP: "0.0.0.0",
143-
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
142+
HostPort: strconv.Itoa(in.Node.HTTPPort),
144143
},
145144
},
146145
nat.Port(innerDebuggerPort): []nat.PortBinding{
147146
{
148147
HostIP: "0.0.0.0",
149-
HostPort: debuggerPort,
148+
HostPort: strconv.Itoa(in.Node.DebuggerPort),
150149
},
151150
},
152151
}
@@ -160,7 +159,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
160159
customPorts = append(customPorts, fmt.Sprintf("%s/tcp", pp[1]))
161160

162161
dockerPort := nat.Port(fmt.Sprintf("%s/tcp", pp[1]))
163-
hostPort := fmt.Sprintf("%s/tcp", pp[0])
162+
hostPort := pp[0]
164163
portBindings[dockerPort] = []nat.PortBinding{
165164
{
166165
HostIP: "0.0.0.0",
@@ -171,7 +170,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
171170
customPorts = append(customPorts, fmt.Sprintf("%s/tcp", p))
172171

173172
dockerPort := nat.Port(fmt.Sprintf("%s/tcp", p))
174-
hostPort := fmt.Sprintf("%s/tcp", p)
173+
hostPort := p
175174
portBindings[dockerPort] = []nat.PortBinding{
176175
{
177176
HostIP: "0.0.0.0",

framework/components/postgres/postgres.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/testcontainers/testcontainers-go"
1010
tcwait "github.com/testcontainers/testcontainers-go/wait"
1111
"os"
12+
"strconv"
1213
"strings"
1314
"time"
1415
)
@@ -121,7 +122,7 @@ func NewPostgreSQL(in *Input) (*Output, error) {
121122
nat.Port(bindPort): []nat.PortBinding{
122123
{
123124
HostIP: "0.0.0.0",
124-
HostPort: fmt.Sprintf("%d/tcp", portToExpose),
125+
HostPort: strconv.Itoa(portToExpose),
125126
},
126127
},
127128
}

framework/docker.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ func GetHost(container tc.Container) (string, error) {
4747
return host, nil
4848
}
4949

50-
func MapTheSamePort(port string) nat.PortMap {
51-
return nat.PortMap{
52-
nat.Port(port): []nat.PortBinding{
50+
func MapTheSamePort(ports ...string) nat.PortMap {
51+
portMap := nat.PortMap{}
52+
for _, port := range ports {
53+
// need to split off /tcp or /udp
54+
onlyPort := strings.SplitN(port, "/", 2)
55+
portMap[nat.Port(port)] = []nat.PortBinding{
5356
{
5457
HostIP: "0.0.0.0",
55-
HostPort: port,
58+
HostPort: onlyPort[0],
5659
},
57-
},
60+
}
5861
}
62+
return portMap
5963
}
6064

6165
func DefaultTCLabels() map[string]string {

0 commit comments

Comments
 (0)