Skip to content

Commit

Permalink
Add method to get the IP address a port is bound to (#95)
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Edwards <colin@recursivepenguin.com>
  • Loading branch information
DDRBoxman authored and arekkas committed Jul 29, 2017
1 parent 6d57cd4 commit a7951f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ func (r *Resource) GetPort(id string) string {
return m[0].HostPort
}

func (r *Resource) GetBoundIP(id string) string {
if r.Container == nil {
return ""
} else if r.Container.NetworkSettings == nil {
return ""
}

m, ok := r.Container.NetworkSettings.Ports[dc.Port(id)]
if !ok {
return ""
} else if len(m) == 0 {
return ""
}

return m[0].HostIP
}

// NewTLSPool creates a new pool given an endpoint and the certificate path. This is required for endpoints that
// require TLS communication.
func NewTLSPool(endpoint, certpath string) (*Pool, error) {
Expand Down
2 changes: 2 additions & 0 deletions dockertest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func TestPostgres(t *testing.T) {
require.Nil(t, err)
assert.NotEmpty(t, resource.GetPort("5432/tcp"))

assert.NotEmpty(t, resource.GetBoundIP("5432/tcp"))

err = pool.Retry(func() error {
db, err := sql.Open("postgres", fmt.Sprintf("postgres://postgres:secret@localhost:%s/postgres?sslmode=disable", resource.GetPort("5432/tcp")))
if err != nil {
Expand Down

0 comments on commit a7951f7

Please sign in to comment.