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
7 changes: 3 additions & 4 deletions cli/command/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"io"

"github.com/moby/moby/api/types"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/image"
Expand Down Expand Up @@ -39,7 +38,7 @@ type fakeClient struct {
containerStopFunc func(ctx context.Context, containerID string, options container.StopOptions) error
containerKillFunc func(ctx context.Context, containerID, signal string) error
containerPruneFunc func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
containerAttachFunc func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error)
containerAttachFunc func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error)
containerDiffFunc func(ctx context.Context, containerID string) ([]container.FilesystemChange, error)
containerRenameFunc func(ctx context.Context, oldName, newName string) error
containerCommitFunc func(ctx context.Context, container string, options container.CommitOptions) (container.CommitResponse, error)
Expand Down Expand Up @@ -195,11 +194,11 @@ func (f *fakeClient) ContainerStop(ctx context.Context, containerID string, opti
return nil
}

func (f *fakeClient) ContainerAttach(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
func (f *fakeClient) ContainerAttach(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
if f.containerAttachFunc != nil {
return f.containerAttachFunc(ctx, containerID, options)
}
return types.HijackedResponse{}, nil
return client.HijackedResponse{}, nil
}

func (f *fakeClient) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error) {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/docker/cli/cli/command"
"github.com/moby/moby/api/stdcopy"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"github.com/moby/term"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -38,7 +38,7 @@ type hijackedIOStreamer struct {
outputStream io.Writer
errorStream io.Writer

resp types.HijackedResponse
resp client.HijackedResponse

tty bool
detachKeys string
Expand Down
17 changes: 9 additions & 8 deletions cli/command/container/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/pflag"
"gotest.tools/v3/assert"
Expand Down Expand Up @@ -85,14 +86,14 @@ func TestRunAttach(t *testing.T) {
ID: "id",
}, nil
},
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
server, client := net.Pipe()
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
server, clientConn := net.Pipe()
conn = server
t.Cleanup(func() {
_ = server.Close()
})
attachCh <- struct{}{}
return types.NewHijackedResponse(client, types.MediaTypeRawStream), nil
return client.NewHijackedResponse(clientConn, types.MediaTypeRawStream), nil
},
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
responseChan := make(chan container.WaitResponse, 1)
Expand Down Expand Up @@ -162,14 +163,14 @@ func TestRunAttachTermination(t *testing.T) {
}
return nil
},
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
server, client := net.Pipe()
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
server, clientConn := net.Pipe()
conn = server
t.Cleanup(func() {
_ = server.Close()
})
attachCh <- struct{}{}
return types.NewHijackedResponse(client, types.MediaTypeRawStream), nil
return client.NewHijackedResponse(clientConn, types.MediaTypeRawStream), nil
},
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
responseChan := make(chan container.WaitResponse, 1)
Expand Down Expand Up @@ -233,8 +234,8 @@ func TestRunPullTermination(t *testing.T) {
) (container.CreateResponse, error) {
return container.CreateResponse{}, errors.New("shouldn't try to create a container")
},
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
return types.HijackedResponse{}, errors.New("shouldn't try to attach to a container")
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (client.HijackedResponse, error) {
return client.HijackedResponse{}, errors.New("shouldn't try to attach to a container")
},
imageCreateFunc: func(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error) {
server, client := net.Pipe()
Expand Down
16 changes: 3 additions & 13 deletions cli/command/formatter/displayutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"unicode/utf8"

"github.com/moby/moby/client/pkg/stringid"
"golang.org/x/text/width"
)

Expand All @@ -27,23 +28,12 @@ func charWidth(r rune) int {
}
}

const shortLen = 12

// TruncateID returns a shorthand version of a string identifier for presentation,
// after trimming digest algorithm prefix (if any).
//
// This function is a copy of [stringid.TruncateID] for presentation / formatting
// purposes.
//
// [stringid.TruncateID]: https://github.com/moby/moby/blob/v28.3.2/pkg/stringid/stringid.go#L19
// This function is a wrapper for [stringid.TruncateID] for convenience.
func TruncateID(id string) string {
if i := strings.IndexRune(id, ':'); i >= 0 {
id = id[i+1:]
}
if len(id) > shortLen {
id = id[:shortLen]
}
return id
return stringid.TruncateID(id)
}

// Ellipsis truncates a string to fit within maxDisplayWidth, and appends ellipsis (…).
Expand Down
24 changes: 12 additions & 12 deletions cli/command/plugin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,45 @@ import (

type fakeClient struct {
client.Client
pluginCreateFunc func(createContext io.Reader, createOptions types.PluginCreateOptions) error
pluginDisableFunc func(name string, disableOptions types.PluginDisableOptions) error
pluginEnableFunc func(name string, options types.PluginEnableOptions) error
pluginRemoveFunc func(name string, options types.PluginRemoveOptions) error
pluginInstallFunc func(name string, options types.PluginInstallOptions) (io.ReadCloser, error)
pluginCreateFunc func(createContext io.Reader, createOptions client.PluginCreateOptions) error
pluginDisableFunc func(name string, disableOptions client.PluginDisableOptions) error
pluginEnableFunc func(name string, options client.PluginEnableOptions) error
pluginRemoveFunc func(name string, options client.PluginRemoveOptions) error
pluginInstallFunc func(name string, options client.PluginInstallOptions) (io.ReadCloser, error)
pluginListFunc func(filter filters.Args) (types.PluginsListResponse, error)
pluginInspectFunc func(name string) (*types.Plugin, []byte, error)
pluginUpgradeFunc func(name string, options types.PluginInstallOptions) (io.ReadCloser, error)
pluginUpgradeFunc func(name string, options client.PluginInstallOptions) (io.ReadCloser, error)
}

func (c *fakeClient) PluginCreate(_ context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error {
func (c *fakeClient) PluginCreate(_ context.Context, createContext io.Reader, createOptions client.PluginCreateOptions) error {
if c.pluginCreateFunc != nil {
return c.pluginCreateFunc(createContext, createOptions)
}
return nil
}

func (c *fakeClient) PluginEnable(_ context.Context, name string, enableOptions types.PluginEnableOptions) error {
func (c *fakeClient) PluginEnable(_ context.Context, name string, enableOptions client.PluginEnableOptions) error {
if c.pluginEnableFunc != nil {
return c.pluginEnableFunc(name, enableOptions)
}
return nil
}

func (c *fakeClient) PluginDisable(_ context.Context, name string, disableOptions types.PluginDisableOptions) error {
func (c *fakeClient) PluginDisable(_ context.Context, name string, disableOptions client.PluginDisableOptions) error {
if c.pluginDisableFunc != nil {
return c.pluginDisableFunc(name, disableOptions)
}
return nil
}

func (c *fakeClient) PluginRemove(_ context.Context, name string, removeOptions types.PluginRemoveOptions) error {
func (c *fakeClient) PluginRemove(_ context.Context, name string, removeOptions client.PluginRemoveOptions) error {
if c.pluginRemoveFunc != nil {
return c.pluginRemoveFunc(name, removeOptions)
}
return nil
}

func (c *fakeClient) PluginInstall(_ context.Context, name string, installOptions types.PluginInstallOptions) (io.ReadCloser, error) {
func (c *fakeClient) PluginInstall(_ context.Context, name string, installOptions client.PluginInstallOptions) (io.ReadCloser, error) {
if c.pluginInstallFunc != nil {
return c.pluginInstallFunc(name, installOptions)
}
Expand All @@ -77,7 +77,7 @@ func (*fakeClient) Info(context.Context) (system.Info, error) {
return system.Info{}, nil
}

func (c *fakeClient) PluginUpgrade(_ context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
func (c *fakeClient) PluginUpgrade(_ context.Context, name string, options client.PluginInstallOptions) (io.ReadCloser, error) {
if c.pluginUpgradeFunc != nil {
return c.pluginUpgradeFunc(name, options)
}
Expand Down
3 changes: 2 additions & 1 deletion cli/command/plugin/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/moby/go-archive"
"github.com/moby/go-archive/compression"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -113,7 +114,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options pluginCreateO
return err
}

err = dockerCli.Client().PluginCreate(ctx, createCtx, types.PluginCreateOptions{RepoName: options.repoName})
err = dockerCli.Client().PluginCreate(ctx, createCtx, client.PluginCreateOptions{RepoName: options.repoName})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cli/command/plugin/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/docker/cli/internal/test"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/fs"
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestCreateErrorFromDaemon(t *testing.T) {
defer tmpDir.Remove()

cmd := newCreateCommand(test.NewFakeCli(&fakeClient{
pluginCreateFunc: func(createContext io.Reader, createOptions types.PluginCreateOptions) error {
pluginCreateFunc: func(createContext io.Reader, createOptions client.PluginCreateOptions) error {
return errors.New("error creating plugin")
},
}))
Expand All @@ -113,7 +113,7 @@ func TestCreatePlugin(t *testing.T) {
defer tmpDir.Remove()

cli := test.NewFakeCli(&fakeClient{
pluginCreateFunc: func(createContext io.Reader, createOptions types.PluginCreateOptions) error {
pluginCreateFunc: func(createContext io.Reader, createOptions client.PluginCreateOptions) error {
return nil
},
})
Expand Down
4 changes: 2 additions & 2 deletions cli/command/plugin/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)

func newDisableCommand(dockerCLI command.Cli) *cobra.Command {
var opts types.PluginDisableOptions
var opts client.PluginDisableOptions

cmd := &cobra.Command{
Use: "disable [OPTIONS] PLUGIN",
Expand Down
8 changes: 4 additions & 4 deletions cli/command/plugin/disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/docker/cli/internal/test"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand All @@ -15,7 +15,7 @@ func TestPluginDisableErrors(t *testing.T) {
testCases := []struct {
args []string
expectedError string
pluginDisableFunc func(name string, disableOptions types.PluginDisableOptions) error
pluginDisableFunc func(name string, disableOptions client.PluginDisableOptions) error
}{
{
args: []string{},
Expand All @@ -28,7 +28,7 @@ func TestPluginDisableErrors(t *testing.T) {
{
args: []string{"plugin-foo"},
expectedError: "error disabling plugin",
pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error {
pluginDisableFunc: func(name string, disableOptions client.PluginDisableOptions) error {
return errors.New("error disabling plugin")
},
},
Expand All @@ -48,7 +48,7 @@ func TestPluginDisableErrors(t *testing.T) {

func TestPluginDisable(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error {
pluginDisableFunc: func(name string, disableOptions client.PluginDisableOptions) error {
return nil
},
})
Expand Down
6 changes: 3 additions & 3 deletions cli/command/plugin/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func newEnableCommand(dockerCli command.Cli) *cobra.Command {
var opts types.PluginEnableOptions
var opts client.PluginEnableOptions

cmd := &cobra.Command{
Use: "enable [OPTIONS] PLUGIN",
Expand All @@ -33,7 +33,7 @@ func newEnableCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}

func runEnable(ctx context.Context, dockerCli command.Cli, name string, opts types.PluginEnableOptions) error {
func runEnable(ctx context.Context, dockerCli command.Cli, name string, opts client.PluginEnableOptions) error {
if opts.Timeout < 0 {
return errors.Errorf("negative timeout %d is invalid", opts.Timeout)
}
Expand Down
8 changes: 4 additions & 4 deletions cli/command/plugin/enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/docker/cli/internal/test"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand All @@ -15,7 +15,7 @@ func TestPluginEnableErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
pluginEnableFunc func(name string, options types.PluginEnableOptions) error
pluginEnableFunc func(name string, options client.PluginEnableOptions) error
expectedError string
}{
{
Expand All @@ -28,7 +28,7 @@ func TestPluginEnableErrors(t *testing.T) {
},
{
args: []string{"plugin-foo"},
pluginEnableFunc: func(name string, options types.PluginEnableOptions) error {
pluginEnableFunc: func(name string, options client.PluginEnableOptions) error {
return errors.New("failed to enable plugin")
},
expectedError: "failed to enable plugin",
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestPluginEnableErrors(t *testing.T) {

func TestPluginEnable(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
pluginEnableFunc: func(name string, options types.PluginEnableOptions) error {
pluginEnableFunc: func(name string, options client.PluginEnableOptions) error {
return nil
},
})
Expand Down
Loading
Loading