Skip to content

Commit 4619817

Browse files
authored
Merge pull request #21 from mbobrovskyi/master
Add ExposePorts Option
2 parents 072d182 + 109fc3b commit 4619817

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

dktest.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ func runImage(ctx context.Context, lgr Logger, dc client.ContainerAPIClient, img
6868
opts Options) (ContainerInfo, error) {
6969
c := ContainerInfo{Name: genContainerName(), ImageName: imgName}
7070
createResp, err := dc.ContainerCreate(ctx, &container.Config{
71-
Image: imgName,
72-
Labels: map[string]string{label: "true"},
73-
Env: opts.env(),
74-
Entrypoint: opts.Entrypoint,
75-
Cmd: opts.Cmd,
76-
Volumes: opts.volumes(),
77-
Hostname: opts.Hostname,
71+
Image: imgName,
72+
Labels: map[string]string{label: "true"},
73+
Env: opts.env(),
74+
Entrypoint: opts.Entrypoint,
75+
Cmd: opts.Cmd,
76+
Volumes: opts.volumes(),
77+
Hostname: opts.Hostname,
78+
ExposedPorts: opts.ExposedPorts,
7879
}, &container.HostConfig{
7980
PublishAllPorts: true,
8081
PortBindings: opts.PortBindings,

dktest_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,20 @@ func TestRunWithNetworkPortBinding(t *testing.T) {
9494
dktest.Run(t, testNetworkImage, dktest.Options{ReadyFunc: nginxReady, PortRequired: true,
9595
PortBindings: nat.PortMap{port: []nat.PortBinding{{HostPort: "8181"}}}}, noop)
9696
}
97+
98+
func TestRunWithExposesPorts(t *testing.T) {
99+
port, err := nat.NewPort("tcp", "8080")
100+
if err != nil {
101+
t.Fatal("Invalid port:", err)
102+
}
103+
104+
dktest.Run(t, testNetworkImage, dktest.Options{
105+
ReadyFunc: nginxReady,
106+
PortRequired: true,
107+
ExposedPorts: nat.PortSet{port: struct{}{}},
108+
}, func(t *testing.T, info dktest.ContainerInfo) {
109+
if _, ok := info.Ports[port]; !ok {
110+
t.Fatal("port not exposed")
111+
}
112+
})
113+
}

options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ type Options struct {
3636
Mounts []mount.Mount
3737
Hostname string
3838
// Platform specifies the platform of the docker image that is pulled.
39-
Platform string
39+
Platform string
40+
ExposedPorts nat.PortSet
4041
}
4142

4243
func (o *Options) init() {

0 commit comments

Comments
 (0)