Skip to content

Commit 4e881c0

Browse files
authored
chore(test): replace deprecated docker struct types in testing harness (#9549)
**Description** `types.Container` and `types.ContainerJSON` from the docker page are deprecated. The documentation says they are going to be removed in the next release. This MR replaces the deprecated types throughout the code base with their modern equivalents. Also changed `container` to `c` in `GetContainer()`, so the variable doesn't collide with the package name.
1 parent c2c4f2d commit 4e881c0

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

t/t.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"syscall"
2727
"time"
2828

29-
"github.com/docker/docker/api/types"
3029
"github.com/docker/docker/api/types/container"
3130
"github.com/docker/docker/api/types/filters"
3231
"github.com/docker/docker/api/types/network"
@@ -790,7 +789,7 @@ func removeAllTestContainers() {
790789
var wg sync.WaitGroup
791790
for _, c := range containers {
792791
wg.Add(1)
793-
go func(c types.Container) {
792+
go func(c container.Summary) {
794793
defer wg.Done()
795794
o := container.StopOptions{Timeout: &dur}
796795
err := cli.ContainerStop(ctxb, c.ID, o)

testutil/docker.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"strings"
1818
"time"
1919

20-
"github.com/docker/docker/api/types"
2120
"github.com/docker/docker/api/types/container"
2221
"github.com/docker/docker/client"
2322
"github.com/golang/glog"
@@ -151,7 +150,7 @@ func (in ContainerInstance) bestEffortTryLogin() error {
151150
return nil
152151
}
153152
if strings.Contains(err.Error(), "Client sent an HTTP request to an HTTPS server.") {
154-
// This is TLS enabled cluster. We won't be able to login.
153+
// This is a TLS enabled cluster. We won't be able to log in.
155154
return nil
156155
}
157156
fmt.Printf("login failed for %s: %v. Retrying...\n", in, err)
@@ -161,21 +160,21 @@ func (in ContainerInstance) bestEffortTryLogin() error {
161160
return fmt.Errorf("unable to login to %s", in)
162161
}
163162

164-
func (in ContainerInstance) GetContainer() *types.Container {
163+
func (in ContainerInstance) GetContainer() *container.Summary {
165164
containers := AllContainers(in.Prefix)
166165

167166
q := fmt.Sprintf("/%s_%s_", in.Prefix, in.Name)
168-
for _, container := range containers {
169-
for _, name := range container.Names {
167+
for _, c := range containers {
168+
for _, name := range c.Names {
170169
if strings.HasPrefix(name, q) {
171-
return &container
170+
return &c
172171
}
173172
}
174173
}
175174
return nil
176175
}
177176

178-
func getContainer(name string) types.Container {
177+
func getContainer(name string) container.Summary {
179178
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
180179
x.Check(err)
181180

@@ -193,10 +192,10 @@ func getContainer(name string) types.Container {
193192
return c
194193
}
195194
}
196-
return types.Container{}
195+
return container.Summary{}
197196
}
198197

199-
func AllContainers(prefix string) []types.Container {
198+
func AllContainers(prefix string) []container.Summary {
200199
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
201200
x.Check(err)
202201

@@ -205,7 +204,7 @@ func AllContainers(prefix string) []types.Container {
205204
log.Fatalf("While listing container: %v\n", err)
206205
}
207206

208-
var out []types.Container
207+
var out []container.Summary
209208
for _, c := range containers {
210209
for _, name := range c.Names {
211210
if strings.HasPrefix(name, "/"+prefix) {
@@ -234,7 +233,7 @@ func ContainerAddr(name string, privatePort uint16) string {
234233
return ContainerAddrWithHost(name, privatePort, "0.0.0.0")
235234
}
236235

237-
// DockerStart starts the specified services.
236+
// DockerRun performs the specified operation on the given container instance.
238237
func DockerRun(instance string, op int) error {
239238
c := getContainer(instance)
240239
if c.ID == "" {
@@ -299,7 +298,7 @@ func DockerExec(instance string, cmd ...string) error {
299298
return Exec(argv...)
300299
}
301300

302-
func DockerInspect(containerID string) (types.ContainerJSON, error) {
301+
func DockerInspect(containerID string) (container.InspectResponse, error) {
303302
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
304303
x.Check(err)
305304
return cli.ContainerInspect(context.Background(), containerID)

0 commit comments

Comments
 (0)