Skip to content

Commit b7100a8

Browse files
ewildearekkas
authored andcommitted
Adds name and host name to RunWithOptions
1 parent 0c237ab commit b7100a8

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Gopkg.lock

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dockertest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ func shouldPreferTls(endpoint string) bool {
119119

120120
// RunOptions is used to pass in optional parameters when running a container.
121121
type RunOptions struct {
122+
Hostname string
123+
Name string
122124
Repository string
123125
Tag string
124126
Env []string
@@ -178,7 +180,9 @@ func (d *Pool) RunWithOptions(opts *RunOptions) (*Resource, error) {
178180
}
179181

180182
c, err := d.Client.CreateContainer(dc.CreateContainerOptions{
183+
Name: opts.Name,
181184
Config: &dc.Config{
185+
Hostname: opts.Hostname,
182186
Image: fmt.Sprintf("%s:%s", repository, tag),
183187
Env: env,
184188
Entrypoint: ep,

dockertest_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ func TestMongo(t *testing.T) {
7272
require.Nil(t, err)
7373
require.Nil(t, pool.Purge(resource))
7474
}
75+
76+
func TestContainerWithName(t *testing.T) {
77+
resource, err := pool.RunWithOptions(
78+
&RunOptions{
79+
Name: "db",
80+
Repository: "postgres",
81+
Tag: "9.5",
82+
})
83+
require.Nil(t, err)
84+
assert.Equal(t,"/db", resource.Container.Name)
85+
86+
require.Nil(t, pool.Purge(resource))
87+
}

0 commit comments

Comments
 (0)