dockertest icon indicating copy to clipboard operation
dockertest copied to clipboard

Trying to bind to an outbound ip returns an empty list of port bindings

Open atzoum opened this issue 1 year ago • 1 comments
trafficstars

Preflight checklist

Ory Network Project

No response

Describe the bug

Using a PortBindings for an outbound ip causes an empty mapped port to be returned

Reproducing the bug

func TestOutboundIPPortBinding(t *testing.T) {
	outboundIP := func() string {
		conn, err := net.Dial("udp", "8.8.8.8:80")
		require.NoError(t, err)
		defer conn.Close()
		localAddr := conn.LocalAddr().(*net.UDPAddr)
		return localAddr.IP.String()
	}()
	resource, err := pool.RunWithOptions(
		&dockertest.RunOptions{
			Repository: "postgres",
			Tag:        "9.5",
			Env:        []string{"POSTGRES_PASSWORD=secret"},
			PortBindings: map[dc.Port][]dc.PortBinding{
				"5432/tcp": {{HostIP: outboundIP, HostPort: "0"}},
			},
		})
	require.NoError(t, err)
	mappedPort := resource.GetPort("5432/tcp")
	require.NotEmpty(t, mappedPort)
	boundIP := resource.GetBoundIP("5432/tcp")
	require.Equal(t, outboundIP, boundIP)
	require.NoError(t, pool.Purge(resource))
}

Relevant log output

No response

Relevant configuration

No response

Version

latest dockertest

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

None

Additional Context

No response

atzoum avatar Sep 25 '24 07:09 atzoum

I have prepared a fix in #533

atzoum avatar Sep 25 '24 07:09 atzoum