Skip to content

Commit 6f39165

Browse files
committed
add command and volumes params
1 parent 88b640f commit 6f39165

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

wrapper.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ type AfterInitActionFunc func(hostname string, port int) error
1818
type WrapperParams struct {
1919
ImageName string
2020
ImageTag string
21-
EnvVariables []string
2221
ContainerPort string
22+
EnvVariables []string
23+
Volumes []string
24+
Command []string
2325
AfterInitActionFunc AfterInitActionFunc
2426
}
2527

2628
// WrapperInstance holds all the information of the running container
2729
type WrapperInstance struct {
28-
Hostname string
29-
Port int
30-
DockerHost string // deprecated
31-
HostPort int // deprecated
32-
Pool *dockertest.Pool
33-
Resource *dockertest.Resource
30+
Hostname string
31+
Port int
32+
Pool *dockertest.Pool
33+
Resource *dockertest.Resource
3434
}
3535

3636
// InitContainer starts a new container with the given parameters
@@ -41,7 +41,15 @@ func InitContainer(params WrapperParams) (instance *WrapperInstance, err error)
4141
return nil, err
4242
}
4343

44-
instance.Resource, err = instance.Pool.Run(params.ImageName, params.ImageTag, params.EnvVariables)
44+
runOpts := dockertest.RunOptions{
45+
Repository: params.ImageName,
46+
Tag: params.ImageTag,
47+
Env: params.EnvVariables,
48+
Cmd: params.Command,
49+
Mounts: params.Volumes,
50+
}
51+
52+
instance.Resource, err = instance.Pool.RunWithOptions(&runOpts)
4553
if err != nil {
4654
return nil, err
4755
}
@@ -76,7 +84,6 @@ func (w WrapperInstance) PurgeContainer() error {
7684
func (w *WrapperInstance) determineHostname() error {
7785
if strings.HasPrefix(w.Pool.Client.Endpoint(), "unix://") {
7886
w.Hostname = "localhost"
79-
w.DockerHost = w.Hostname // will be removed in a future update
8087
return nil
8188
}
8289

@@ -87,7 +94,6 @@ func (w *WrapperInstance) determineHostname() error {
8794
}
8895

8996
w.Hostname = endpointUrl.Hostname()
90-
w.DockerHost = w.Hostname // will be removed in a future update
9197
return nil
9298
}
9399

@@ -98,6 +104,5 @@ func (w *WrapperInstance) determinePort(containerPort string) (err error) {
98104
return err
99105
}
100106

101-
w.HostPort = w.Port // will be remove in a future update
102107
return nil
103108
}

wrapper_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var wrapperInstanceDetermineHostnameTests = []struct {
2424
doAssertions: func(t *testing.T, actualInstance WrapperInstance, actualErr error) {
2525
assert.NoError(t, actualErr)
2626
assert.Equal(t, "localhost", actualInstance.Hostname)
27-
assert.Equal(t, "localhost", actualInstance.DockerHost) // will be removed in a future update
2827
},
2928
},
3029
{
@@ -33,7 +32,6 @@ var wrapperInstanceDetermineHostnameTests = []struct {
3332
doAssertions: func(t *testing.T, actualInstance WrapperInstance, actualErr error) {
3433
assert.NoError(t, actualErr)
3534
assert.Equal(t, "docker", actualInstance.Hostname)
36-
assert.Equal(t, "docker", actualInstance.DockerHost) // will be removed in a future update
3735
},
3836
},
3937
}
@@ -73,7 +71,6 @@ var wrapperInstanceDeterminePortTests = []struct {
7371
doAssertions: func(t *testing.T, instance WrapperInstance, actualErr error) {
7472
assert.Error(t, actualErr)
7573
assert.Equal(t, 0, instance.Port)
76-
assert.Equal(t, 0, instance.HostPort) // will be removed in a future update
7774
},
7875
},
7976
{
@@ -83,7 +80,6 @@ var wrapperInstanceDeterminePortTests = []struct {
8380
doAssertions: func(t *testing.T, instance WrapperInstance, actualErr error) {
8481
assert.NoError(t, actualErr)
8582
assert.Equal(t, 5432, instance.Port)
86-
assert.Equal(t, 5432, instance.HostPort) // will be removed in a future update
8783
},
8884
},
8985
}

0 commit comments

Comments
 (0)