Skip to content

Commit

Permalink
feat: expose tty in RunOptions (#269)
Browse files Browse the repository at this point in the history
Closes #268

Signed-off-by: Xin Li <xin.li@hedera.com>
  • Loading branch information
xin-hedera committed May 27, 2021
1 parent 142b1d7 commit 888a43c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dockertest.go
Expand Up @@ -301,6 +301,7 @@ type RunOptions struct {
PortBindings map[dc.Port][]dc.PortBinding
Privileged bool
User string
Tty bool
}

// BuildOptions is used to pass in optional parameters when building a container
Expand Down Expand Up @@ -435,6 +436,7 @@ func (d *Pool) RunWithOptions(opts *RunOptions, hcOpts ...func(*dc.HostConfig))
Labels: opts.Labels,
StopSignal: "SIGWINCH", // to support timeouts
User: opts.User,
Tty: opts.Tty,
},
HostConfig: &hostConfig,
NetworkingConfig: &networkingConfig,
Expand Down
19 changes: 19 additions & 0 deletions dockertest_test.go
Expand Up @@ -129,6 +129,25 @@ func TestContainerWithUser(t *testing.T) {
require.Nil(t, pool.Purge(resource))
}

func TestContainerWithTty(t *testing.T) {
resource, err := pool.RunWithOptions(
&RunOptions{
Name: "db",
Repository: "postgres",
Tag: "9.5",
Env: []string{"POSTGRES_PASSWORD=secret"},
Tty: true,
})
require.Nil(t, err)
assert.True(t, resource.Container.Config.Tty, "tty is false")

res, err := pool.Client.InspectContainer(resource.Container.ID)
require.Nil(t, err)
assert.True(t, res.Config.Tty)

require.Nil(t, pool.Purge(resource))
}

func TestContainerWithPortBinding(t *testing.T) {
resource, err := pool.RunWithOptions(
&RunOptions{
Expand Down
5 changes: 1 addition & 4 deletions go.sum
Expand Up @@ -8,8 +8,7 @@ github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -26,8 +25,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2 h1:hRGSmZu7j271trc9sneMrpOW7GN5ngLm8YUZIPzf394=
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/moby/term v0.0.0-20200915141129-7f0af18e79f2 h1:SPoLlS9qUUnXcIY4pvA4CTwYjk0Is5f4UPEkeESr53k=
github.com/moby/term v0.0.0-20200915141129-7f0af18e79f2/go.mod h1:TjQg8pa4iejrUrjiz0MCtMV38jdMNW4doKSiBrEvCQQ=
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 h1:rzf0wL0CHVc8CEsgyygG0Mn9CNCCPZqOPaz8RiiHYQk=
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
Expand Down

0 comments on commit 888a43c

Please sign in to comment.