Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions dktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ func runImage(ctx context.Context, lgr Logger, dc client.ContainerAPIClient, img
opts Options) (ContainerInfo, error) {
c := ContainerInfo{Name: genContainerName(), ImageName: imgName}
createResp, err := dc.ContainerCreate(ctx, &container.Config{
Image: imgName,
Labels: map[string]string{label: "true"},
Env: opts.env(),
Entrypoint: opts.Entrypoint,
Cmd: opts.Cmd,
Volumes: opts.volumes(),
Hostname: opts.Hostname,
Image: imgName,
Labels: map[string]string{label: "true"},
Env: opts.env(),
Entrypoint: opts.Entrypoint,
Cmd: opts.Cmd,
Volumes: opts.volumes(),
Hostname: opts.Hostname,
ExposedPorts: opts.ExposedPorts,
}, &container.HostConfig{
PublishAllPorts: true,
PortBindings: opts.PortBindings,
Expand Down
17 changes: 17 additions & 0 deletions dktest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,20 @@ func TestRunWithNetworkPortBinding(t *testing.T) {
dktest.Run(t, testNetworkImage, dktest.Options{ReadyFunc: nginxReady, PortRequired: true,
PortBindings: nat.PortMap{port: []nat.PortBinding{{HostPort: "8181"}}}}, noop)
}

func TestRunWithExposesPorts(t *testing.T) {
port, err := nat.NewPort("tcp", "8080")
if err != nil {
t.Fatal("Invalid port:", err)
}

dktest.Run(t, testNetworkImage, dktest.Options{
ReadyFunc: nginxReady,
PortRequired: true,
ExposedPorts: nat.PortSet{port: struct{}{}},
}, func(t *testing.T, info dktest.ContainerInfo) {
if _, ok := info.Ports[port]; !ok {
t.Fatal("port not exposed")
}
})
}
3 changes: 2 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type Options struct {
Mounts []mount.Mount
Hostname string
// Platform specifies the platform of the docker image that is pulled.
Platform string
Platform string
ExposedPorts nat.PortSet
}

func (o *Options) init() {
Expand Down