replace uses of deprecated API types

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-07-03 15:35:44 +02:00
parent 4cac8efb56
commit b194274beb
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
20 changed files with 153 additions and 160 deletions

View File

@ -4,7 +4,6 @@ import (
"os" "os"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
@ -44,7 +43,7 @@ func ImageNames(dockerCLI APIClientProvider) ValidArgsFn {
// ContainerNames offers completion for container names and IDs // ContainerNames offers completion for container names and IDs
// By default, only names are returned. // By default, only names are returned.
// Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs. // Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs.
func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(types.Container) bool) ValidArgsFn { func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(container.Summary) bool) ValidArgsFn {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().ContainerList(cmd.Context(), container.ListOptions{ list, err := dockerCLI.Client().ContainerList(cmd.Context(), container.ListOptions{
All: all, All: all,

View File

@ -7,7 +7,6 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/moby/sys/signal" "github.com/moby/sys/signal"
@ -23,7 +22,7 @@ type AttachOptions struct {
DetachKeys string DetachKeys string
} }
func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*types.ContainerJSON, error) { func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*container.InspectResponse, error) {
c, err := apiClient.ContainerInspect(ctx, args) c, err := apiClient.ContainerInspect(ctx, args)
if err != nil { if err != nil {
return nil, err return nil, err
@ -56,7 +55,7 @@ func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container attach, docker attach", "aliases": "docker container attach, docker attach",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr container.Summary) bool {
return ctr.State != "paused" return ctr.State != "paused"
}), }),
} }

View File

@ -6,7 +6,6 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -17,24 +16,24 @@ func TestNewAttachCommandErrors(t *testing.T) {
name string name string
args []string args []string
expectedError string expectedError string
containerInspectFunc func(img string) (types.ContainerJSON, error) containerInspectFunc func(img string) (container.InspectResponse, error)
}{ }{
{ {
name: "client-error", name: "client-error",
args: []string{"5cb5bb5e4a3b"}, args: []string{"5cb5bb5e4a3b"},
expectedError: "something went wrong", expectedError: "something went wrong",
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return types.ContainerJSON{}, errors.Errorf("something went wrong") return container.InspectResponse{}, errors.Errorf("something went wrong")
}, },
}, },
{ {
name: "client-stopped", name: "client-stopped",
args: []string{"5cb5bb5e4a3b"}, args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a stopped container", expectedError: "You cannot attach to a stopped container",
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return types.ContainerJSON{ return container.InspectResponse{
ContainerJSONBase: &types.ContainerJSONBase{ ContainerJSONBase: &container.ContainerJSONBase{
State: &types.ContainerState{ State: &container.State{
Running: false, Running: false,
}, },
}, },
@ -45,10 +44,10 @@ func TestNewAttachCommandErrors(t *testing.T) {
name: "client-paused", name: "client-paused",
args: []string{"5cb5bb5e4a3b"}, args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a paused container", expectedError: "You cannot attach to a paused container",
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return types.ContainerJSON{ return container.InspectResponse{
ContainerJSONBase: &types.ContainerJSONBase{ ContainerJSONBase: &container.ContainerJSONBase{
State: &types.ContainerState{ State: &container.State{
Running: true, Running: true,
Paused: true, Paused: true,
}, },
@ -60,10 +59,10 @@ func TestNewAttachCommandErrors(t *testing.T) {
name: "client-restarting", name: "client-restarting",
args: []string{"5cb5bb5e4a3b"}, args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a restarting container", expectedError: "You cannot attach to a restarting container",
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return types.ContainerJSON{ return container.InspectResponse{
ContainerJSONBase: &types.ContainerJSONBase{ ContainerJSONBase: &container.ContainerJSONBase{
State: &types.ContainerState{ State: &container.State{
Running: true, Running: true,
Paused: false, Paused: false,
Restarting: true, Restarting: true,

View File

@ -16,7 +16,7 @@ import (
type fakeClient struct { type fakeClient struct {
client.Client client.Client
inspectFunc func(string) (types.ContainerJSON, error) inspectFunc func(string) (container.InspectResponse, error)
execInspectFunc func(execID string) (container.ExecInspect, error) execInspectFunc func(execID string) (container.ExecInspect, error)
execCreateFunc func(containerID string, options container.ExecOptions) (types.IDResponse, error) execCreateFunc func(containerID string, options container.ExecOptions) (types.IDResponse, error)
createContainerFunc func(config *container.Config, createContainerFunc func(config *container.Config,
@ -31,7 +31,7 @@ type fakeClient struct {
containerCopyFromFunc func(containerID, srcPath string) (io.ReadCloser, container.PathStat, error) containerCopyFromFunc func(containerID, srcPath string) (io.ReadCloser, container.PathStat, error)
logFunc func(string, container.LogsOptions) (io.ReadCloser, error) logFunc func(string, container.LogsOptions) (io.ReadCloser, error)
waitFunc func(string) (<-chan container.WaitResponse, <-chan error) waitFunc func(string) (<-chan container.WaitResponse, <-chan error)
containerListFunc func(container.ListOptions) ([]types.Container, error) containerListFunc func(container.ListOptions) ([]container.Summary, error)
containerExportFunc func(string) (io.ReadCloser, error) containerExportFunc func(string) (io.ReadCloser, error)
containerExecResizeFunc func(id string, options container.ResizeOptions) error containerExecResizeFunc func(id string, options container.ResizeOptions) error
containerRemoveFunc func(ctx context.Context, containerID string, options container.RemoveOptions) error containerRemoveFunc func(ctx context.Context, containerID string, options container.RemoveOptions) error
@ -41,18 +41,18 @@ type fakeClient struct {
Version string Version string
} }
func (f *fakeClient) ContainerList(_ context.Context, options container.ListOptions) ([]types.Container, error) { func (f *fakeClient) ContainerList(_ context.Context, options container.ListOptions) ([]container.Summary, error) {
if f.containerListFunc != nil { if f.containerListFunc != nil {
return f.containerListFunc(options) return f.containerListFunc(options)
} }
return []types.Container{}, nil return []container.Summary{}, nil
} }
func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (types.ContainerJSON, error) { func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (container.InspectResponse, error) {
if f.inspectFunc != nil { if f.inspectFunc != nil {
return f.inspectFunc(containerID) return f.inspectFunc(containerID)
} }
return types.ContainerJSON{}, nil return container.InspectResponse{}, nil
} }
func (f *fakeClient) ContainerExecCreate(_ context.Context, containerID string, config container.ExecOptions) (types.IDResponse, error) { func (f *fakeClient) ContainerExecCreate(_ context.Context, containerID string, config container.ExecOptions) (types.IDResponse, error) {

View File

@ -11,7 +11,6 @@ import (
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -54,7 +53,7 @@ func NewExecCommand(dockerCli command.Cli) *cobra.Command {
options.Command = args[1:] options.Command = args[1:]
return RunExec(cmd.Context(), dockerCli, containerIDorName, options) return RunExec(cmd.Context(), dockerCli, containerIDorName, options)
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool {
return ctr.State != "paused" return ctr.State != "paused"
}), }),
Annotations: map[string]string{ Annotations: map[string]string{

View File

@ -178,8 +178,8 @@ func TestRunExec(t *testing.T) {
doc: "inspect error", doc: "inspect error",
options: NewExecOptions(), options: NewExecOptions(),
client: &fakeClient{ client: &fakeClient{
inspectFunc: func(string) (types.ContainerJSON, error) { inspectFunc: func(string) (container.InspectResponse, error) {
return types.ContainerJSON{}, errors.New("failed inspect") return container.InspectResponse{}, errors.New("failed inspect")
}, },
}, },
expectedError: "failed inspect", expectedError: "failed inspect",
@ -252,14 +252,14 @@ func TestNewExecCommandErrors(t *testing.T) {
name string name string
args []string args []string
expectedError string expectedError string
containerInspectFunc func(img string) (types.ContainerJSON, error) containerInspectFunc func(img string) (container.InspectResponse, error)
}{ }{
{ {
name: "client-error", name: "client-error",
args: []string{"5cb5bb5e4a3b", "-t", "-i", "bash"}, args: []string{"5cb5bb5e4a3b", "-t", "-i", "bash"},
expectedError: "something went wrong", expectedError: "something went wrong",
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return types.ContainerJSON{}, errors.Errorf("something went wrong") return container.InspectResponse{}, errors.Errorf("something went wrong")
}, },
}, },
} }

View File

@ -9,7 +9,6 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders" "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
@ -130,7 +129,7 @@ func TestContainerListErrors(t *testing.T) {
testCases := []struct { testCases := []struct {
args []string args []string
flags map[string]string flags map[string]string
containerListFunc func(container.ListOptions) ([]types.Container, error) containerListFunc func(container.ListOptions) ([]container.Summary, error)
expectedError string expectedError string
}{ }{
{ {
@ -146,7 +145,7 @@ func TestContainerListErrors(t *testing.T) {
expectedError: `wrong number of args for join`, expectedError: `wrong number of args for join`,
}, },
{ {
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return nil, errors.New("error listing containers") return nil, errors.New("error listing containers")
}, },
expectedError: "error listing containers", expectedError: "error listing containers",
@ -170,8 +169,8 @@ func TestContainerListErrors(t *testing.T) {
func TestContainerListWithoutFormat(t *testing.T) { func TestContainerListWithoutFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return []types.Container{ return []container.Summary{
*builders.Container("c1"), *builders.Container("c1"),
*builders.Container("c2", builders.WithName("foo")), *builders.Container("c2", builders.WithName("foo")),
*builders.Container("c3", builders.WithPort(80, 80, builders.TCP), builders.WithPort(81, 81, builders.TCP), builders.WithPort(82, 82, builders.TCP)), *builders.Container("c3", builders.WithPort(80, 80, builders.TCP), builders.WithPort(81, 81, builders.TCP), builders.WithPort(82, 82, builders.TCP)),
@ -187,8 +186,8 @@ func TestContainerListWithoutFormat(t *testing.T) {
func TestContainerListNoTrunc(t *testing.T) { func TestContainerListNoTrunc(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return []types.Container{ return []container.Summary{
*builders.Container("c1"), *builders.Container("c1"),
*builders.Container("c2", builders.WithName("foo/bar")), *builders.Container("c2", builders.WithName("foo/bar")),
}, nil }, nil
@ -203,8 +202,8 @@ func TestContainerListNoTrunc(t *testing.T) {
// Test for GitHub issue docker/docker#21772 // Test for GitHub issue docker/docker#21772
func TestContainerListNamesMultipleTime(t *testing.T) { func TestContainerListNamesMultipleTime(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return []types.Container{ return []container.Summary{
*builders.Container("c1"), *builders.Container("c1"),
*builders.Container("c2", builders.WithName("foo/bar")), *builders.Container("c2", builders.WithName("foo/bar")),
}, nil }, nil
@ -219,8 +218,8 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
// Test for GitHub issue docker/docker#30291 // Test for GitHub issue docker/docker#30291
func TestContainerListFormatTemplateWithArg(t *testing.T) { func TestContainerListFormatTemplateWithArg(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return []types.Container{ return []container.Summary{
*builders.Container("c1", builders.WithLabel("some.label", "value")), *builders.Container("c1", builders.WithLabel("some.label", "value")),
*builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")), *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")),
}, nil }, nil
@ -270,9 +269,9 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) {
tc := tc tc := tc
t.Run(tc.doc, func(t *testing.T) { t.Run(tc.doc, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(options container.ListOptions) ([]types.Container, error) { containerListFunc: func(options container.ListOptions) ([]container.Summary, error) {
assert.Check(t, is.Equal(options.Size, tc.sizeExpected)) assert.Check(t, is.Equal(options.Size, tc.sizeExpected))
return []types.Container{}, nil return []container.Summary{}, nil
}, },
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
@ -287,8 +286,8 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) {
func TestContainerListWithConfigFormat(t *testing.T) { func TestContainerListWithConfigFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return []types.Container{ return []container.Summary{
*builders.Container("c1", builders.WithLabel("some.label", "value"), builders.WithSize(10700000)), *builders.Container("c1", builders.WithLabel("some.label", "value"), builders.WithSize(10700000)),
*builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar"), builders.WithSize(3200000)), *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar"), builders.WithSize(3200000)),
}, nil }, nil
@ -304,8 +303,8 @@ func TestContainerListWithConfigFormat(t *testing.T) {
func TestContainerListWithFormat(t *testing.T) { func TestContainerListWithFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) {
return []types.Container{ return []container.Summary{
*builders.Container("c1", builders.WithLabel("some.label", "value")), *builders.Container("c1", builders.WithLabel("some.label", "value")),
*builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")), *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")),
}, nil }, nil

View File

@ -7,7 +7,6 @@ import (
"testing" "testing"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
@ -20,10 +19,10 @@ var logFn = func(expectedOut string) func(string, container.LogsOptions) (io.Rea
} }
func TestRunLogs(t *testing.T) { func TestRunLogs(t *testing.T) {
inspectFn := func(containerID string) (types.ContainerJSON, error) { inspectFn := func(containerID string) (container.InspectResponse, error) {
return types.ContainerJSON{ return container.InspectResponse{
Config: &container.Config{Tty: true}, Config: &container.Config{Tty: true},
ContainerJSONBase: &types.ContainerJSONBase{State: &types.ContainerState{Running: false}}, ContainerJSONBase: &container.ContainerJSONBase{State: &container.State{Running: false}},
}, nil }, nil
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -32,7 +32,7 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container pause, docker pause", "aliases": "docker container pause, docker pause",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool {
return ctr.State != "paused" return ctr.State != "paused"
}), }),
} }

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
@ -46,8 +46,8 @@ func TestNewPortCommandOutput(t *testing.T) {
tc := tc tc := tc
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
inspectFunc: func(string) (types.ContainerJSON, error) { inspectFunc: func(string) (container.InspectResponse, error) {
ci := types.ContainerJSON{NetworkSettings: &types.NetworkSettings{}} ci := container.InspectResponse{NetworkSettings: &container.NetworkSettings{}}
ci.NetworkSettings.Ports = nat.PortMap{ ci.NetworkSettings.Ports = nat.PortMap{
"80/tcp": make([]nat.PortBinding, len(tc.ips)), "80/tcp": make([]nat.PortBinding, len(tc.ips)),
"443/tcp": make([]nat.PortBinding, len(tc.ips)), "443/tcp": make([]nat.PortBinding, len(tc.ips)),

View File

@ -9,7 +9,6 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/moby/sys/signal" "github.com/moby/sys/signal"
"github.com/moby/term" "github.com/moby/term"
@ -43,7 +42,7 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container start, docker start", "aliases": "docker container start, docker start",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr container.Summary) bool {
return ctr.State == "exited" || ctr.State == "created" return ctr.State == "exited" || ctr.State == "created"
}), }),
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -32,7 +32,7 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container unpause, docker unpause", "aliases": "docker container unpause, docker unpause",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool {
return ctr.State == "paused" return ctr.State == "paused"
}), }),
} }

View File

@ -11,7 +11,7 @@ import (
"time" "time"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units" "github.com/docker/go-units"
) )
@ -66,7 +66,7 @@ ports: {{- pad .Ports 1 0}}
} }
// ContainerWrite renders the context for a list of containers // ContainerWrite renders the context for a list of containers
func ContainerWrite(ctx Context, containers []types.Container) error { func ContainerWrite(ctx Context, containers []container.Summary) error {
render := func(format func(subContext SubContext) error) error { render := func(format func(subContext SubContext) error) error {
for _, ctr := range containers { for _, ctr := range containers {
err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr}) err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr})
@ -83,7 +83,7 @@ func ContainerWrite(ctx Context, containers []types.Container) error {
type ContainerContext struct { type ContainerContext struct {
HeaderContext HeaderContext
trunc bool trunc bool
c types.Container c container.Summary
// FieldsUsed is used in the pre-processing step to detect which fields are // FieldsUsed is used in the pre-processing step to detect which fields are
// used in the template. It's currently only used to detect use of the .Size // used in the template. It's currently only used to detect use of the .Size
@ -313,7 +313,7 @@ func (c *ContainerContext) Networks() string {
// DisplayablePorts returns formatted string representing open ports of container // DisplayablePorts returns formatted string representing open ports of container
// e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" // e.g. "0.0.0.0:80->9090/tcp, 9988/tcp"
// it's used by command 'docker ps' // it's used by command 'docker ps'
func DisplayablePorts(ports []types.Port) string { func DisplayablePorts(ports []container.Port) string {
type portGroup struct { type portGroup struct {
first uint16 first uint16
last uint16 last uint16
@ -378,7 +378,7 @@ func formGroup(key string, start, last uint16) string {
return group + "/" + groupType return group + "/" + groupType
} }
func comparePorts(i, j types.Port) bool { func comparePorts(i, j container.Port) bool {
if i.PrivatePort != j.PrivatePort { if i.PrivatePort != j.PrivatePort {
return i.PrivatePort < j.PrivatePort return i.PrivatePort < j.PrivatePort
} }

View File

@ -12,7 +12,7 @@ import (
"time" "time"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
@ -25,47 +25,47 @@ func TestContainerPsContext(t *testing.T) {
var ctx ContainerContext var ctx ContainerContext
cases := []struct { cases := []struct {
container types.Container container container.Summary
trunc bool trunc bool
expValue string expValue string
call func() string call func() string
}{ }{
{ {
container: types.Container{ID: containerID}, container: container.Summary{ID: containerID},
trunc: true, trunc: true,
expValue: stringid.TruncateID(containerID), expValue: stringid.TruncateID(containerID),
call: ctx.ID, call: ctx.ID,
}, },
{ {
container: types.Container{ID: containerID}, container: container.Summary{ID: containerID},
expValue: containerID, expValue: containerID,
call: ctx.ID, call: ctx.ID,
}, },
{ {
container: types.Container{Names: []string{"/foobar_baz"}}, container: container.Summary{Names: []string{"/foobar_baz"}},
trunc: true, trunc: true,
expValue: "foobar_baz", expValue: "foobar_baz",
call: ctx.Names, call: ctx.Names,
}, },
{ {
container: types.Container{Image: "ubuntu"}, container: container.Summary{Image: "ubuntu"},
trunc: true, trunc: true,
expValue: "ubuntu", expValue: "ubuntu",
call: ctx.Image, call: ctx.Image,
}, },
{ {
container: types.Container{Image: "verylongimagename"}, container: container.Summary{Image: "verylongimagename"},
trunc: true, trunc: true,
expValue: "verylongimagename", expValue: "verylongimagename",
call: ctx.Image, call: ctx.Image,
}, },
{ {
container: types.Container{Image: "verylongimagename"}, container: container.Summary{Image: "verylongimagename"},
expValue: "verylongimagename", expValue: "verylongimagename",
call: ctx.Image, call: ctx.Image,
}, },
{ {
container: types.Container{ container: container.Summary{
Image: "a5a665ff33eced1e0803148700880edab4", Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
}, },
@ -74,7 +74,7 @@ func TestContainerPsContext(t *testing.T) {
call: ctx.Image, call: ctx.Image,
}, },
{ {
container: types.Container{ container: container.Summary{
Image: "a5a665ff33eced1e0803148700880edab4", Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
}, },
@ -82,67 +82,67 @@ func TestContainerPsContext(t *testing.T) {
call: ctx.Image, call: ctx.Image,
}, },
{ {
container: types.Container{Image: ""}, container: container.Summary{Image: ""},
trunc: true, trunc: true,
expValue: "<no image>", expValue: "<no image>",
call: ctx.Image, call: ctx.Image,
}, },
{ {
container: types.Container{Command: "sh -c 'ls -la'"}, container: container.Summary{Command: "sh -c 'ls -la'"},
trunc: true, trunc: true,
expValue: `"sh -c 'ls -la'"`, expValue: `"sh -c 'ls -la'"`,
call: ctx.Command, call: ctx.Command,
}, },
{ {
container: types.Container{Created: unix}, container: container.Summary{Created: unix},
trunc: true, trunc: true,
expValue: time.Unix(unix, 0).String(), expValue: time.Unix(unix, 0).String(),
call: ctx.CreatedAt, call: ctx.CreatedAt,
}, },
{ {
container: types.Container{Ports: []types.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, container: container.Summary{Ports: []container.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}},
trunc: true, trunc: true,
expValue: "8080/tcp", expValue: "8080/tcp",
call: ctx.Ports, call: ctx.Ports,
}, },
{ {
container: types.Container{Status: "RUNNING"}, container: container.Summary{Status: "RUNNING"},
trunc: true, trunc: true,
expValue: "RUNNING", expValue: "RUNNING",
call: ctx.Status, call: ctx.Status,
}, },
{ {
container: types.Container{SizeRw: 10}, container: container.Summary{SizeRw: 10},
trunc: true, trunc: true,
expValue: "10B", expValue: "10B",
call: ctx.Size, call: ctx.Size,
}, },
{ {
container: types.Container{SizeRw: 10, SizeRootFs: 20}, container: container.Summary{SizeRw: 10, SizeRootFs: 20},
trunc: true, trunc: true,
expValue: "10B (virtual 20B)", expValue: "10B (virtual 20B)",
call: ctx.Size, call: ctx.Size,
}, },
{ {
container: types.Container{}, container: container.Summary{},
trunc: true, trunc: true,
call: ctx.Labels, call: ctx.Labels,
}, },
{ {
container: types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, container: container.Summary{Labels: map[string]string{"cpu": "6", "storage": "ssd"}},
trunc: true, trunc: true,
expValue: "cpu=6,storage=ssd", expValue: "cpu=6,storage=ssd",
call: ctx.Labels, call: ctx.Labels,
}, },
{ {
container: types.Container{Created: unix}, container: container.Summary{Created: unix},
trunc: true, trunc: true,
expValue: "About a minute ago", expValue: "About a minute ago",
call: ctx.RunningFor, call: ctx.RunningFor,
}, },
{ {
container: types.Container{ container: container.Summary{
Mounts: []types.MountPoint{ Mounts: []container.MountPoint{
{ {
Name: "this-is-a-long-volume-name-and-will-be-truncated-if-trunc-is-set", Name: "this-is-a-long-volume-name-and-will-be-truncated-if-trunc-is-set",
Driver: "local", Driver: "local",
@ -155,8 +155,8 @@ func TestContainerPsContext(t *testing.T) {
call: ctx.Mounts, call: ctx.Mounts,
}, },
{ {
container: types.Container{ container: container.Summary{
Mounts: []types.MountPoint{ Mounts: []container.MountPoint{
{ {
Driver: "local", Driver: "local",
Source: "/a/path", Source: "/a/path",
@ -167,8 +167,8 @@ func TestContainerPsContext(t *testing.T) {
call: ctx.Mounts, call: ctx.Mounts,
}, },
{ {
container: types.Container{ container: container.Summary{
Mounts: []types.MountPoint{ Mounts: []container.MountPoint{
{ {
Name: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203", Name: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203",
Driver: "local", Driver: "local",
@ -191,7 +191,7 @@ func TestContainerPsContext(t *testing.T) {
} }
} }
c1 := types.Container{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}} c1 := container.Summary{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}}
ctx = ContainerContext{c: c1, trunc: true} ctx = ContainerContext{c: c1, trunc: true}
sid := ctx.Label("com.docker.swarm.swarm-id") sid := ctx.Label("com.docker.swarm.swarm-id")
@ -204,7 +204,7 @@ func TestContainerPsContext(t *testing.T) {
t.Fatalf("Expected ubuntu, was %s\n", node) t.Fatalf("Expected ubuntu, was %s\n", node)
} }
c2 := types.Container{} c2 := container.Summary{}
ctx = ContainerContext{c: c2, trunc: true} ctx = ContainerContext{c: c2, trunc: true}
label := ctx.Label("anything.really") label := ctx.Label("anything.really")
@ -340,7 +340,7 @@ size: 0B
}, },
} }
containers := []types.Container{ containers := []container.Summary{
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime, State: "running"}, {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime, State: "running"},
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime, State: "running"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime, State: "running"},
} }
@ -362,7 +362,7 @@ size: 0B
func TestContainerContextWriteWithNoContainers(t *testing.T) { func TestContainerContextWriteWithNoContainers(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
containers := []types.Container{} containers := []container.Summary{}
cases := []struct { cases := []struct {
context Context context Context
@ -424,7 +424,7 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
func TestContainerContextWriteJSON(t *testing.T) { func TestContainerContextWriteJSON(t *testing.T) {
unix := time.Now().Add(-65 * time.Second).Unix() unix := time.Now().Add(-65 * time.Second).Unix()
containers := []types.Container{ containers := []container.Summary{
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unix, State: "running"}, {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unix, State: "running"},
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unix, State: "running"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unix, State: "running"},
} }
@ -478,7 +478,7 @@ func TestContainerContextWriteJSON(t *testing.T) {
} }
func TestContainerContextWriteJSONField(t *testing.T) { func TestContainerContextWriteJSONField(t *testing.T) {
containers := []types.Container{ containers := []container.Summary{
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu"}, {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu"},
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu"},
} }
@ -497,7 +497,7 @@ func TestContainerContextWriteJSONField(t *testing.T) {
} }
func TestContainerBackCompat(t *testing.T) { func TestContainerBackCompat(t *testing.T) {
containers := []types.Container{{ID: "brewhaha"}} containers := []container.Summary{{ID: "brewhaha"}}
cases := []string{ cases := []string{
"ID", "ID",
"Names", "Names",
@ -523,7 +523,7 @@ func TestContainerBackCompat(t *testing.T) {
} }
type ports struct { type ports struct {
ports []types.Port ports []container.Port
expected string expected string
} }
@ -531,7 +531,7 @@ type ports struct {
func TestDisplayablePorts(t *testing.T) { func TestDisplayablePorts(t *testing.T) {
cases := []ports{ cases := []ports{
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 9988, PrivatePort: 9988,
Type: "tcp", Type: "tcp",
@ -540,7 +540,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9988/tcp", expected: "9988/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 9988, PrivatePort: 9988,
Type: "udp", Type: "udp",
@ -549,7 +549,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9988/udp", expected: "9988/udp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "0.0.0.0", IP: "0.0.0.0",
PrivatePort: 9988, PrivatePort: 9988,
@ -559,7 +559,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "0.0.0.0:0->9988/tcp", expected: "0.0.0.0:0->9988/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 9988, PrivatePort: 9988,
PublicPort: 8899, PublicPort: 8899,
@ -569,7 +569,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9988/tcp", expected: "9988/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "4.3.2.1", IP: "4.3.2.1",
PrivatePort: 9988, PrivatePort: 9988,
@ -580,7 +580,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "4.3.2.1:8899->9988/tcp", expected: "4.3.2.1:8899->9988/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "4.3.2.1", IP: "4.3.2.1",
PrivatePort: 9988, PrivatePort: 9988,
@ -591,7 +591,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "4.3.2.1:9988->9988/tcp", expected: "4.3.2.1:9988->9988/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 9988, PrivatePort: 9988,
Type: "udp", Type: "udp",
@ -603,7 +603,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9988/udp, 9988/udp", expected: "9988/udp, 9988/udp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "1.2.3.4", IP: "1.2.3.4",
PublicPort: 9998, PublicPort: 9998,
@ -619,7 +619,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "1.2.3.4:9998-9999->9998-9999/udp", expected: "1.2.3.4:9998-9999->9998-9999/udp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "1.2.3.4", IP: "1.2.3.4",
PublicPort: 8887, PublicPort: 8887,
@ -635,7 +635,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp", expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 9998, PrivatePort: 9998,
Type: "udp", Type: "udp",
@ -647,7 +647,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9998-9999/udp", expected: "9998-9999/udp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "1.2.3.4", IP: "1.2.3.4",
PrivatePort: 6677, PrivatePort: 6677,
@ -662,7 +662,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9988/udp, 1.2.3.4:7766->6677/tcp", expected: "9988/udp, 1.2.3.4:7766->6677/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
IP: "1.2.3.4", IP: "1.2.3.4",
PrivatePort: 9988, PrivatePort: 9988,
@ -683,7 +683,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp", expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 9988, PrivatePort: 9988,
PublicPort: 8899, PublicPort: 8899,
@ -703,7 +703,7 @@ func TestDisplayablePorts(t *testing.T) {
expected: "9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp", expected: "9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp",
}, },
{ {
ports: []types.Port{ ports: []container.Port{
{ {
PrivatePort: 80, PrivatePort: 80,
Type: "tcp", Type: "tcp",

View File

@ -9,6 +9,7 @@ import (
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
units "github.com/docker/go-units" units "github.com/docker/go-units"
@ -36,7 +37,7 @@ type DiskUsageContext struct {
Verbose bool Verbose bool
LayersSize int64 LayersSize int64
Images []*image.Summary Images []*image.Summary
Containers []*types.Container Containers []*container.Summary
Volumes []*volume.Volume Volumes []*volume.Volume
BuildCache []*types.BuildCache BuildCache []*types.BuildCache
BuilderSize int64 BuilderSize int64
@ -124,7 +125,7 @@ func (ctx *DiskUsageContext) Write() (err error) {
return err return err
} }
diskUsageContainersCtx := diskUsageContainersContext{containers: []*types.Container{}} diskUsageContainersCtx := diskUsageContainersContext{containers: []*container.Summary{}}
diskUsageContainersCtx.Header = SubHeaderContext{ diskUsageContainersCtx.Header = SubHeaderContext{
"Type": typeHeader, "Type": typeHeader,
"TotalCount": totalHeader, "TotalCount": totalHeader,
@ -313,7 +314,7 @@ func (c *diskUsageImagesContext) Reclaimable() string {
type diskUsageContainersContext struct { type diskUsageContainersContext struct {
HeaderContext HeaderContext
containers []*types.Container containers []*container.Summary
} }
func (c *diskUsageContainersContext) MarshalJSON() ([]byte, error) { func (c *diskUsageContainersContext) MarshalJSON() ([]byte, error) {
@ -328,10 +329,10 @@ func (c *diskUsageContainersContext) TotalCount() string {
return strconv.Itoa(len(c.containers)) return strconv.Itoa(len(c.containers))
} }
func (c *diskUsageContainersContext) isActive(container types.Container) bool { func (c *diskUsageContainersContext) isActive(ctr container.Summary) bool {
return strings.Contains(container.State, "running") || return strings.Contains(ctr.State, "running") ||
strings.Contains(container.State, "paused") || strings.Contains(ctr.State, "paused") ||
strings.Contains(container.State, "restarting") strings.Contains(ctr.State, "restarting")
} }
func (c *diskUsageContainersContext) Active() string { func (c *diskUsageContainersContext) Active() string {

View File

@ -24,7 +24,7 @@ type fakeClient struct {
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error) imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error) imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error)
imageListFunc func(options image.ListOptions) ([]image.Summary, error) imageListFunc func(options image.ListOptions) ([]image.Summary, error)
imageInspectFunc func(img string) (types.ImageInspect, []byte, error) imageInspectFunc func(img string) (image.InspectResponse, []byte, error)
imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error) imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error) imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error)
@ -95,11 +95,11 @@ func (cli *fakeClient) ImageList(_ context.Context, options image.ListOptions) (
return []image.Summary{}, nil return []image.Summary{}, nil
} }
func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, img string) (types.ImageInspect, []byte, error) { func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, img string) (image.InspectResponse, []byte, error) {
if cli.imageInspectFunc != nil { if cli.imageInspectFunc != nil {
return cli.imageInspectFunc(img) return cli.imageInspectFunc(img)
} }
return types.ImageInspect{}, nil, nil return image.InspectResponse{}, nil, nil
} }
func (cli *fakeClient) ImageImport(_ context.Context, source image.ImportSource, ref string, func (cli *fakeClient) ImageImport(_ context.Context, source image.ImportSource, ref string,

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/image"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
@ -42,39 +42,39 @@ func TestNewInspectCommandSuccess(t *testing.T) {
name string name string
args []string args []string
imageCount int imageCount int
imageInspectFunc func(img string) (types.ImageInspect, []byte, error) imageInspectFunc func(img string) (image.InspectResponse, []byte, error)
}{ }{
{ {
name: "simple", name: "simple",
args: []string{"image"}, args: []string{"image"},
imageCount: 1, imageCount: 1,
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(img string) (image.InspectResponse, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
assert.Check(t, is.Equal("image", img)) assert.Check(t, is.Equal("image", img))
return types.ImageInspect{}, nil, nil return image.InspectResponse{}, nil, nil
}, },
}, },
{ {
name: "format", name: "format",
imageCount: 1, imageCount: 1,
args: []string{"--format='{{.ID}}'", "image"}, args: []string{"--format='{{.ID}}'", "image"},
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(img string) (image.InspectResponse, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
return types.ImageInspect{ID: img}, nil, nil return image.InspectResponse{ID: img}, nil, nil
}, },
}, },
{ {
name: "simple-many", name: "simple-many",
args: []string{"image1", "image2"}, args: []string{"image1", "image2"},
imageCount: 2, imageCount: 2,
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(img string) (image.InspectResponse, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
if imageInspectInvocationCount == 1 { if imageInspectInvocationCount == 1 {
assert.Check(t, is.Equal("image1", img)) assert.Check(t, is.Equal("image1", img))
} else { } else {
assert.Check(t, is.Equal("image2", img)) assert.Check(t, is.Equal("image2", img))
} }
return types.ImageInspect{}, nil, nil return image.InspectResponse{}, nil, nil
}, },
}, },
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -48,8 +48,8 @@ func runDisconnect(ctx context.Context, apiClient client.NetworkAPIClient, opts
return apiClient.NetworkDisconnect(ctx, opts.network, opts.container, opts.force) return apiClient.NetworkDisconnect(ctx, opts.network, opts.container, opts.force)
} }
func isConnected(network string) func(types.Container) bool { func isConnected(network string) func(container.Summary) bool {
return func(ctr types.Container) bool { return func(ctr container.Summary) bool {
if ctr.NetworkSettings == nil { if ctr.NetworkSettings == nil {
return false return false
} }
@ -58,8 +58,8 @@ func isConnected(network string) func(types.Container) bool {
} }
} }
func not(fn func(types.Container) bool) func(types.Container) bool { func not(fn func(container.Summary) bool) func(container.Summary) bool {
return func(ctr types.Container) bool { return func(ctr container.Summary) bool {
ok := fn(ctr) ok := fn(ctr)
return !ok return !ok
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/docker/cli/cli/trust" "github.com/docker/cli/cli/trust"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
notaryfake "github.com/docker/cli/internal/test/notary" notaryfake "github.com/docker/cli/internal/test/notary"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/system" "github.com/docker/docker/api/types/system"
"github.com/docker/docker/client" "github.com/docker/docker/client"
@ -33,8 +32,8 @@ func (c *fakeClient) Info(context.Context) (system.Info, error) {
return system.Info{}, nil return system.Info{}, nil
} }
func (c *fakeClient) ImageInspectWithRaw(context.Context, string) (types.ImageInspect, []byte, error) { func (c *fakeClient) ImageInspectWithRaw(context.Context, string) (image.InspectResponse, []byte, error) {
return types.ImageInspect{}, []byte{}, nil return image.InspectResponse{}, []byte{}, nil
} }
func (c *fakeClient) ImagePush(context.Context, string, image.PushOptions) (io.ReadCloser, error) { func (c *fakeClient) ImagePush(context.Context, string, image.PushOptions) (io.ReadCloser, error) {

View File

@ -3,15 +3,15 @@ package builders
import ( import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
) )
// Container creates a container with default values. // Container creates a container with default values.
// Any number of container function builder can be passed to augment it. // Any number of container function builder can be passed to augment it.
func Container(name string, builders ...func(c *types.Container)) *types.Container { func Container(name string, builders ...func(c *container.Summary)) *container.Summary {
// now := time.Now() // now := time.Now()
// onehourago := now.Add(-120 * time.Minute) // onehourago := now.Add(-120 * time.Minute)
ctr := &types.Container{ ctr := &container.Summary{
ID: "container_id", ID: "container_id",
Names: []string{"/" + name}, Names: []string{"/" + name},
Command: "top", Command: "top",
@ -28,8 +28,8 @@ func Container(name string, builders ...func(c *types.Container)) *types.Contain
} }
// WithLabel adds a label to the container // WithLabel adds a label to the container
func WithLabel(key, value string) func(*types.Container) { func WithLabel(key, value string) func(*container.Summary) {
return func(c *types.Container) { return func(c *container.Summary) {
if c.Labels == nil { if c.Labels == nil {
c.Labels = map[string]string{} c.Labels = map[string]string{}
} }
@ -38,19 +38,19 @@ func WithLabel(key, value string) func(*types.Container) {
} }
// WithName adds a name to the container // WithName adds a name to the container
func WithName(name string) func(*types.Container) { func WithName(name string) func(*container.Summary) {
return func(c *types.Container) { return func(c *container.Summary) {
c.Names = append(c.Names, "/"+name) c.Names = append(c.Names, "/"+name)
} }
} }
// WithPort adds a port mapping to the container // WithPort adds a port mapping to the container
func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) func(*types.Container) { func WithPort(privatePort, publicPort uint16, builders ...func(*container.Port)) func(*container.Summary) {
return func(c *types.Container) { return func(c *container.Summary) {
if c.Ports == nil { if c.Ports == nil {
c.Ports = []types.Port{} c.Ports = []container.Port{}
} }
port := &types.Port{ port := &container.Port{
PrivatePort: privatePort, PrivatePort: privatePort,
PublicPort: publicPort, PublicPort: publicPort,
} }
@ -62,8 +62,8 @@ func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) fun
} }
// WithSize adds size in bytes to the container // WithSize adds size in bytes to the container
func WithSize(size int64) func(*types.Container) { func WithSize(size int64) func(*container.Summary) {
return func(c *types.Container) { return func(c *container.Summary) {
if size >= 0 { if size >= 0 {
c.SizeRw = size c.SizeRw = size
} }
@ -71,18 +71,18 @@ func WithSize(size int64) func(*types.Container) {
} }
// IP sets the ip of the port // IP sets the ip of the port
func IP(ip string) func(*types.Port) { func IP(ip string) func(*container.Port) {
return func(p *types.Port) { return func(p *container.Port) {
p.IP = ip p.IP = ip
} }
} }
// TCP sets the port to tcp // TCP sets the port to tcp
func TCP(p *types.Port) { func TCP(p *container.Port) {
p.Type = "tcp" p.Type = "tcp"
} }
// UDP sets the port to udp // UDP sets the port to udp
func UDP(p *types.Port) { func UDP(p *container.Port) {
p.Type = "udp" p.Type = "udp"
} }