Skip to content

Commit

Permalink
Adds portbinding to RunWithOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilde authored and arekkas committed Dec 1, 2017
1 parent b7100a8 commit 596a4ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions dockertest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
}

0 comments on commit 596a4ae

Please sign in to comment.