From 596a4ae7da4f7a01a54a565a7b8274acd91f0bf7 Mon Sep 17 00:00:00 2001 From: Edward Wilde Date: Thu, 30 Nov 2017 16:24:27 +0000 Subject: [PATCH] Adds portbinding to RunWithOptions --- dockertest.go | 2 ++ dockertest_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/dockertest.go b/dockertest.go index fedbf2ab..a2cc5c81 100644 --- a/dockertest.go +++ b/dockertest.go @@ -130,6 +130,7 @@ type RunOptions struct { Links []string ExposedPorts []string Auth dc.AuthConfiguration + PortBindings map[dc.Port][]dc.PortBinding } // RunWithOptions starts a docker container. @@ -194,6 +195,7 @@ func (d *Pool) RunWithOptions(opts *RunOptions) (*Resource, error) { PublishAllPorts: true, Binds: opts.Mounts, Links: opts.Links, + PortBindings: opts.PortBindings, }, }) if err != nil { diff --git a/dockertest_test.go b/dockertest_test.go index 22bb1a52..7b056c5b 100644 --- a/dockertest_test.go +++ b/dockertest_test.go @@ -11,6 +11,7 @@ import ( _ "github.com/lib/pq" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dc "github.com/fsouza/go-dockerclient" ) var docker = os.Getenv("DOCKER_URL") @@ -83,5 +84,20 @@ func TestContainerWithName(t *testing.T) { require.Nil(t, err) assert.Equal(t,"/db", resource.Container.Name) + require.Nil(t, pool.Purge(resource)) +} + +func TestContainerWithPortBinding(t *testing.T) { + resource, err := pool.RunWithOptions( + &RunOptions{ + Repository: "postgres", + Tag: "9.5", + PortBindings: map[dc.Port][]dc.PortBinding{ + "5432/tcp": {{HostIP: "", HostPort: "5433"}}, + }, + }) + require.Nil(t, err) + assert.Equal(t,"5433", resource.GetPort("5432/tcp")) + require.Nil(t, pool.Purge(resource)) } \ No newline at end of file