Skip to content
Closed
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
19 changes: 10 additions & 9 deletions dktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,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(),
ExposedPorts: opts.ExposedPorts,
Hostname: opts.Hostname,
}, &container.HostConfig{
PublishAllPorts: true,
PortBindings: opts.PortBindings,
Expand Down Expand Up @@ -126,7 +127,7 @@ func stopContainer(ctx context.Context, lgr Logger, dc client.ContainerAPIClient
}
}

if err := dc.ContainerStop(ctx, c.ID, nil); err != nil {
if err := dc.ContainerStop(ctx, c.ID, container.StopOptions{}); err != nil {
lgr.Log("Error stopping container:", c.String(), "error:", err)
}
lgr.Log("Stopped container:", c.String())
Expand Down Expand Up @@ -179,7 +180,7 @@ func Run(t *testing.T, imgName string, opts Options, testFunc func(*testing.T, C

// RunContext is similar to Run, but takes a parent context and returns an error and doesn't rely on a testing.T.
func RunContext(ctx context.Context, logger Logger, imgName string, opts Options, testFunc func(ContainerInfo) error) (retErr error) {
dc, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
dc, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return fmt.Errorf("error getting Docker client: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/dhui/dktest
require (
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v20.10.24+incompatible
github.com/docker/docker v24.0.5+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand All @@ -14,7 +14,6 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.7.0 // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v20.10.24+incompatible h1:Ugvxm7a8+Gz6vqQYQQ2W7GYq5EUPaAiuPgIfVyI3dYE=
github.com/docker/docker v20.10.24+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v24.0.5+incompatible h1:WmgcE4fxyI6EEXxBRxsHnZXrO1pQ3smi0k/jho4HLeY=
github.com/docker/docker v24.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
Expand Down Expand Up @@ -47,8 +47,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Options struct {
Env map[string]string
Entrypoint []string
Cmd []string
// List of exposed ports
ExposedPorts nat.PortSet
// If you prefer to specify your port bindings as a string, use nat.ParsePortSpecs()
PortBindings nat.PortMap
PortRequired bool
Expand Down