Skip to content

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

@atzoum

Description

@atzoum

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions