vendor: github.com/moby/moby/api, moby/moby/client master
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -35,7 +35,7 @@ type fakeClient struct {
|
||||
containerRestartFunc func(ctx context.Context, containerID string, options client.ContainerStopOptions) error
|
||||
containerStopFunc func(ctx context.Context, containerID string, options client.ContainerStopOptions) error
|
||||
containerKillFunc func(ctx context.Context, containerID, signal string) error
|
||||
containerPruneFunc func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error)
|
||||
containerPruneFunc func(ctx context.Context, options client.ContainerPruneOptions) (client.ContainerPruneResult, error)
|
||||
containerAttachFunc func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.HijackedResponse, error)
|
||||
containerDiffFunc func(ctx context.Context, containerID string) ([]container.FilesystemChange, error)
|
||||
containerRenameFunc func(ctx context.Context, oldName, newName string) error
|
||||
@ -171,11 +171,11 @@ func (f *fakeClient) ContainerKill(ctx context.Context, containerID, signal stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) ContainersPrune(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
|
||||
func (f *fakeClient) ContainersPrune(ctx context.Context, options client.ContainerPruneOptions) (client.ContainerPruneResult, error) {
|
||||
if f.containerPruneFunc != nil {
|
||||
return f.containerPruneFunc(ctx, pruneFilters)
|
||||
return f.containerPruneFunc(ctx, options)
|
||||
}
|
||||
return container.PruneReport{}, nil
|
||||
return client.ContainerPruneResult{}, nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) ContainerRestart(ctx context.Context, containerID string, options client.ContainerStopOptions) error {
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/docker/cli/internal/prompt"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -73,17 +74,19 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||
}
|
||||
}
|
||||
|
||||
report, err := dockerCli.Client().ContainersPrune(ctx, pruneFilters)
|
||||
res, err := dockerCli.Client().ContainersPrune(ctx, client.ContainerPruneOptions{
|
||||
Filters: pruneFilters,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
if len(report.ContainersDeleted) > 0 {
|
||||
if len(res.Report.ContainersDeleted) > 0 {
|
||||
output = "Deleted Containers:\n"
|
||||
for _, id := range report.ContainersDeleted {
|
||||
for _, id := range res.Report.ContainersDeleted {
|
||||
output += id + "\n"
|
||||
}
|
||||
spaceReclaimed = report.SpaceReclaimed
|
||||
spaceReclaimed = res.Report.SpaceReclaimed
|
||||
}
|
||||
|
||||
return spaceReclaimed, output, nil
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/client"
|
||||
)
|
||||
|
||||
@ -16,8 +15,8 @@ func TestContainerPrunePromptTermination(t *testing.T) {
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
containerPruneFunc: func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
|
||||
return container.PruneReport{}, errors.New("fakeClient containerPruneFunc should not be called")
|
||||
containerPruneFunc: func(ctx context.Context, opts client.ContainerPruneOptions) (client.ContainerPruneResult, error) {
|
||||
return client.ContainerPruneResult{}, errors.New("fakeClient containerPruneFunc should not be called")
|
||||
},
|
||||
})
|
||||
cmd := newPruneCommand(cli)
|
||||
|
||||
@ -19,7 +19,7 @@ type fakeClient struct {
|
||||
imagePushFunc func(ref string, options client.ImagePushOptions) (io.ReadCloser, error)
|
||||
infoFunc func() (system.Info, error)
|
||||
imagePullFunc func(ref string, options client.ImagePullOptions) (client.ImagePullResponse, error)
|
||||
imagesPruneFunc func(pruneFilter client.Filters) (image.PruneReport, error)
|
||||
imagesPruneFunc func(options client.ImagePruneOptions) (client.ImagePruneResult, error)
|
||||
imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (client.LoadResponse, error)
|
||||
imageListFunc func(options client.ImageListOptions) ([]image.Summary, error)
|
||||
imageInspectFunc func(img string) (image.InspectResponse, error)
|
||||
@ -72,11 +72,11 @@ func (cli *fakeClient) ImagePull(_ context.Context, ref string, options client.I
|
||||
return client.ImagePullResponse{}, nil
|
||||
}
|
||||
|
||||
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
func (cli *fakeClient) ImagesPrune(_ context.Context, opts client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
if cli.imagesPruneFunc != nil {
|
||||
return cli.imagesPruneFunc(pruneFilter)
|
||||
return cli.imagesPruneFunc(opts)
|
||||
}
|
||||
return image.PruneReport{}, nil
|
||||
return client.ImagePruneResult{}, nil
|
||||
}
|
||||
|
||||
func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, options ...client.ImageLoadOption) (client.LoadResponse, error) {
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/docker/cli/internal/prompt"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -86,15 +87,17 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||
}
|
||||
}
|
||||
|
||||
report, err := dockerCli.Client().ImagesPrune(ctx, pruneFilters)
|
||||
res, err := dockerCli.Client().ImagesPrune(ctx, client.ImagePruneOptions{
|
||||
Filters: pruneFilters,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
if len(report.ImagesDeleted) > 0 {
|
||||
var sb strings.Builder
|
||||
var sb strings.Builder
|
||||
if len(res.Report.ImagesDeleted) > 0 {
|
||||
sb.WriteString("Deleted Images:\n")
|
||||
for _, st := range report.ImagesDeleted {
|
||||
for _, st := range res.Report.ImagesDeleted {
|
||||
if st.Untagged != "" {
|
||||
sb.WriteString("untagged: ")
|
||||
sb.WriteString(st.Untagged)
|
||||
@ -105,11 +108,9 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||
sb.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
output = sb.String()
|
||||
spaceReclaimed = report.SpaceReclaimed
|
||||
}
|
||||
|
||||
return spaceReclaimed, output, nil
|
||||
return res.Report.SpaceReclaimed, sb.String(), nil
|
||||
}
|
||||
|
||||
type cancelledErr struct{ error }
|
||||
|
||||
@ -21,7 +21,7 @@ func TestNewPruneCommandErrors(t *testing.T) {
|
||||
name string
|
||||
args []string
|
||||
expectedError string
|
||||
imagesPruneFunc func(pruneFilter client.Filters) (image.PruneReport, error)
|
||||
imagesPruneFunc func(client.ImagePruneOptions) (client.ImagePruneResult, error)
|
||||
}{
|
||||
{
|
||||
name: "wrong-args",
|
||||
@ -32,8 +32,8 @@ func TestNewPruneCommandErrors(t *testing.T) {
|
||||
name: "prune-error",
|
||||
args: []string{"--force"},
|
||||
expectedError: "something went wrong",
|
||||
imagesPruneFunc: func(pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
return image.PruneReport{}, errors.New("something went wrong")
|
||||
imagesPruneFunc: func(client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
return client.ImagePruneResult{}, errors.New("something went wrong")
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -54,43 +54,47 @@ func TestNewPruneCommandSuccess(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
imagesPruneFunc func(pruneFilter client.Filters) (image.PruneReport, error)
|
||||
imagesPruneFunc func(client.ImagePruneOptions) (client.ImagePruneResult, error)
|
||||
}{
|
||||
{
|
||||
name: "all",
|
||||
args: []string{"--all"},
|
||||
imagesPruneFunc: func(pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
assert.Check(t, pruneFilter["dangling"]["false"])
|
||||
return image.PruneReport{}, nil
|
||||
imagesPruneFunc: func(opts client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
assert.Check(t, opts.Filters["dangling"]["false"])
|
||||
return client.ImagePruneResult{}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "force-deleted",
|
||||
args: []string{"--force"},
|
||||
imagesPruneFunc: func(pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
assert.Check(t, pruneFilter["dangling"]["true"])
|
||||
return image.PruneReport{
|
||||
ImagesDeleted: []image.DeleteResponse{{Deleted: "image1"}},
|
||||
SpaceReclaimed: 1,
|
||||
imagesPruneFunc: func(opts client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
assert.Check(t, opts.Filters["dangling"]["true"])
|
||||
return client.ImagePruneResult{
|
||||
Report: image.PruneReport{
|
||||
ImagesDeleted: []image.DeleteResponse{{Deleted: "image1"}},
|
||||
SpaceReclaimed: 1,
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "label-filter",
|
||||
args: []string{"--force", "--filter", "label=foobar"},
|
||||
imagesPruneFunc: func(pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
assert.Check(t, pruneFilter["label"]["foobar"])
|
||||
return image.PruneReport{}, nil
|
||||
imagesPruneFunc: func(opts client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
assert.Check(t, opts.Filters["label"]["foobar"])
|
||||
return client.ImagePruneResult{}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "force-untagged",
|
||||
args: []string{"--force"},
|
||||
imagesPruneFunc: func(pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
assert.Check(t, pruneFilter["dangling"]["true"])
|
||||
return image.PruneReport{
|
||||
ImagesDeleted: []image.DeleteResponse{{Untagged: "image1"}},
|
||||
SpaceReclaimed: 2,
|
||||
imagesPruneFunc: func(opts client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
assert.Check(t, opts.Filters["dangling"]["true"])
|
||||
return client.ImagePruneResult{
|
||||
Report: image.PruneReport{
|
||||
ImagesDeleted: []image.DeleteResponse{{Untagged: "image1"}},
|
||||
SpaceReclaimed: 2,
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
@ -116,8 +120,8 @@ func TestPrunePromptTermination(t *testing.T) {
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
imagesPruneFunc: func(pruneFilter client.Filters) (image.PruneReport, error) {
|
||||
return image.PruneReport{}, errors.New("fakeClient imagesPruneFunc should not be called")
|
||||
imagesPruneFunc: func(client.ImagePruneOptions) (client.ImagePruneResult, error) {
|
||||
return client.ImagePruneResult{}, errors.New("fakeClient imagesPruneFunc should not be called")
|
||||
},
|
||||
})
|
||||
cmd := newPruneCommand(cli)
|
||||
|
||||
@ -14,7 +14,7 @@ type fakeClient struct {
|
||||
networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error
|
||||
networkRemoveFunc func(ctx context.Context, networkID string) error
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
|
||||
networkPruneFunc func(ctx context.Context, pruneFilters client.Filters) (network.PruneReport, error)
|
||||
networkPruneFunc func(ctx context.Context, options client.NetworkPruneOptions) (client.NetworkPruneResult, error)
|
||||
networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, []byte, error)
|
||||
}
|
||||
|
||||
@ -60,9 +60,9 @@ func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string
|
||||
return network.Inspect{}, nil, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworksPrune(ctx context.Context, pruneFilter client.Filters) (network.PruneReport, error) {
|
||||
func (c *fakeClient) NetworksPrune(ctx context.Context, opts client.NetworkPruneOptions) (client.NetworkPruneResult, error) {
|
||||
if c.networkPruneFunc != nil {
|
||||
return c.networkPruneFunc(ctx, pruneFilter)
|
||||
return c.networkPruneFunc(ctx, opts)
|
||||
}
|
||||
return network.PruneReport{}, nil
|
||||
return client.NetworkPruneResult{}, nil
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/cli/cli/command/system/pruner"
|
||||
"github.com/docker/cli/internal/prompt"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -70,14 +71,16 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||
}
|
||||
}
|
||||
|
||||
report, err := dockerCli.Client().NetworksPrune(ctx, pruneFilters)
|
||||
res, err := dockerCli.Client().NetworksPrune(ctx, client.NetworkPruneOptions{
|
||||
Filters: pruneFilters,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(report.NetworksDeleted) > 0 {
|
||||
if len(res.Report.NetworksDeleted) > 0 {
|
||||
output = "Deleted Networks:\n"
|
||||
for _, id := range report.NetworksDeleted {
|
||||
for _, id := range res.Report.NetworksDeleted {
|
||||
output += id + "\n"
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
)
|
||||
|
||||
@ -16,8 +15,8 @@ func TestNetworkPrunePromptTermination(t *testing.T) {
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
networkPruneFunc: func(ctx context.Context, pruneFilters client.Filters) (network.PruneReport, error) {
|
||||
return network.PruneReport{}, errors.New("fakeClient networkPruneFunc should not be called")
|
||||
networkPruneFunc: func(ctx context.Context, opts client.NetworkPruneOptions) (client.NetworkPruneResult, error) {
|
||||
return client.NetworkPruneResult{}, errors.New("fakeClient networkPruneFunc should not be called")
|
||||
},
|
||||
})
|
||||
cmd := newPruneCommand(cli)
|
||||
|
||||
@ -11,54 +11,54 @@ import (
|
||||
|
||||
type fakeClient struct {
|
||||
client.Client
|
||||
pluginCreateFunc func(createContext io.Reader, createOptions client.PluginCreateOptions) error
|
||||
pluginDisableFunc func(name string, disableOptions client.PluginDisableOptions) error
|
||||
pluginCreateFunc func(createContext io.Reader, options client.PluginCreateOptions) error
|
||||
pluginDisableFunc func(name string, options 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 client.Filters) (plugin.ListResponse, error)
|
||||
pluginListFunc func(options client.PluginListOptions) (plugin.ListResponse, error)
|
||||
pluginInspectFunc func(name string) (*plugin.Plugin, []byte, error)
|
||||
pluginUpgradeFunc func(name string, options client.PluginInstallOptions) (io.ReadCloser, error)
|
||||
}
|
||||
|
||||
func (c *fakeClient) PluginCreate(_ context.Context, createContext io.Reader, createOptions client.PluginCreateOptions) error {
|
||||
func (c *fakeClient) PluginCreate(_ context.Context, createContext io.Reader, options client.PluginCreateOptions) error {
|
||||
if c.pluginCreateFunc != nil {
|
||||
return c.pluginCreateFunc(createContext, createOptions)
|
||||
return c.pluginCreateFunc(createContext, options)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) PluginEnable(_ context.Context, name string, enableOptions client.PluginEnableOptions) error {
|
||||
func (c *fakeClient) PluginEnable(_ context.Context, name string, options client.PluginEnableOptions) error {
|
||||
if c.pluginEnableFunc != nil {
|
||||
return c.pluginEnableFunc(name, enableOptions)
|
||||
return c.pluginEnableFunc(name, options)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) PluginDisable(_ context.Context, name string, disableOptions client.PluginDisableOptions) error {
|
||||
func (c *fakeClient) PluginDisable(_ context.Context, name string, options client.PluginDisableOptions) error {
|
||||
if c.pluginDisableFunc != nil {
|
||||
return c.pluginDisableFunc(name, disableOptions)
|
||||
return c.pluginDisableFunc(name, options)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) PluginRemove(_ context.Context, name string, removeOptions client.PluginRemoveOptions) error {
|
||||
func (c *fakeClient) PluginRemove(_ context.Context, name string, options client.PluginRemoveOptions) error {
|
||||
if c.pluginRemoveFunc != nil {
|
||||
return c.pluginRemoveFunc(name, removeOptions)
|
||||
return c.pluginRemoveFunc(name, options)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) PluginInstall(_ context.Context, name string, installOptions client.PluginInstallOptions) (io.ReadCloser, error) {
|
||||
func (c *fakeClient) PluginInstall(_ context.Context, name string, options client.PluginInstallOptions) (io.ReadCloser, error) {
|
||||
if c.pluginInstallFunc != nil {
|
||||
return c.pluginInstallFunc(name, installOptions)
|
||||
return c.pluginInstallFunc(name, options)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) PluginList(_ context.Context, filter client.Filters) (plugin.ListResponse, error) {
|
||||
func (c *fakeClient) PluginList(_ context.Context, options client.PluginListOptions) (plugin.ListResponse, error) {
|
||||
if c.pluginListFunc != nil {
|
||||
return c.pluginListFunc(filter)
|
||||
return c.pluginListFunc(options)
|
||||
}
|
||||
|
||||
return plugin.ListResponse{}, nil
|
||||
|
||||
@ -32,7 +32,9 @@ func completeNames(dockerCLI completion.APIClientProvider, state pluginState) co
|
||||
// no filter
|
||||
}
|
||||
|
||||
list, err := dockerCLI.Client().PluginList(cmd.Context(), f)
|
||||
list, err := dockerCLI.Client().PluginList(cmd.Context(), client.PluginListOptions{
|
||||
Filters: f,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveError
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
flagsHelper "github.com/docker/cli/cli/flags"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/fvbommel/sortorder"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -46,13 +47,15 @@ func newListCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
}
|
||||
|
||||
func runList(ctx context.Context, dockerCli command.Cli, options listOptions) error {
|
||||
plugins, err := dockerCli.Client().PluginList(ctx, options.filter.Value())
|
||||
resp, err := dockerCli.Client().PluginList(ctx, client.PluginListOptions{
|
||||
Filters: options.filter.Value(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sort.Slice(plugins, func(i, j int) bool {
|
||||
return sortorder.NaturalLess(plugins[i].Name, plugins[j].Name)
|
||||
sort.Slice(resp, func(i, j int) bool {
|
||||
return sortorder.NaturalLess(resp[i].Name, resp[j].Name)
|
||||
})
|
||||
|
||||
format := options.format
|
||||
@ -69,5 +72,5 @@ func runList(ctx context.Context, dockerCli command.Cli, options listOptions) er
|
||||
Format: newFormat(format, options.quiet),
|
||||
Trunc: !options.noTrunc,
|
||||
}
|
||||
return formatWrite(pluginsCtx, plugins)
|
||||
return formatWrite(pluginsCtx, resp)
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ func TestListErrors(t *testing.T) {
|
||||
args []string
|
||||
flags map[string]string
|
||||
expectedError string
|
||||
listFunc func(filter client.Filters) (plugin.ListResponse, error)
|
||||
listFunc func(client.PluginListOptions) (plugin.ListResponse, error)
|
||||
}{
|
||||
{
|
||||
description: "too many arguments",
|
||||
@ -30,7 +30,7 @@ func TestListErrors(t *testing.T) {
|
||||
description: "error listing plugins",
|
||||
args: []string{},
|
||||
expectedError: "error listing plugins",
|
||||
listFunc: func(filter client.Filters) (plugin.ListResponse, error) {
|
||||
listFunc: func(client.PluginListOptions) (plugin.ListResponse, error) {
|
||||
return plugin.ListResponse{}, errors.New("error listing plugins")
|
||||
},
|
||||
},
|
||||
@ -60,7 +60,7 @@ func TestListErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
singlePluginListFunc := func(_ client.Filters) (plugin.ListResponse, error) {
|
||||
singlePluginListFunc := func(client.PluginListOptions) (plugin.ListResponse, error) {
|
||||
return plugin.ListResponse{
|
||||
{
|
||||
ID: "id-foo",
|
||||
@ -78,7 +78,7 @@ func TestList(t *testing.T) {
|
||||
args []string
|
||||
flags map[string]string
|
||||
golden string
|
||||
listFunc func(filter client.Filters) (plugin.ListResponse, error)
|
||||
listFunc func(client.PluginListOptions) (plugin.ListResponse, error)
|
||||
}{
|
||||
{
|
||||
description: "list with no additional flags",
|
||||
@ -93,9 +93,9 @@ func TestList(t *testing.T) {
|
||||
"filter": "foo=bar",
|
||||
},
|
||||
golden: "plugin-list-without-format.golden",
|
||||
listFunc: func(filter client.Filters) (plugin.ListResponse, error) {
|
||||
assert.Check(t, filter["foo"]["bar"])
|
||||
return singlePluginListFunc(filter)
|
||||
listFunc: func(opts client.PluginListOptions) (plugin.ListResponse, error) {
|
||||
assert.Check(t, opts.Filters["foo"]["bar"])
|
||||
return singlePluginListFunc(opts)
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -115,7 +115,7 @@ func TestList(t *testing.T) {
|
||||
"format": "{{ .ID }}",
|
||||
},
|
||||
golden: "plugin-list-with-no-trunc-option.golden",
|
||||
listFunc: func(_ client.Filters) (plugin.ListResponse, error) {
|
||||
listFunc: func(client.PluginListOptions) (plugin.ListResponse, error) {
|
||||
return plugin.ListResponse{
|
||||
{
|
||||
ID: "xyg4z2hiSLO5yTnBJfg4OYia9gKA6Qjd",
|
||||
@ -144,7 +144,7 @@ func TestList(t *testing.T) {
|
||||
"format": "{{ .Name }}",
|
||||
},
|
||||
golden: "plugin-list-sort.golden",
|
||||
listFunc: func(_ client.Filters) (plugin.ListResponse, error) {
|
||||
listFunc: func(client.PluginListOptions) (plugin.ListResponse, error) {
|
||||
return plugin.ListResponse{
|
||||
{
|
||||
ID: "id-1",
|
||||
|
||||
@ -19,12 +19,12 @@ type fakeClient struct {
|
||||
|
||||
version string
|
||||
containerListFunc func(context.Context, client.ContainerListOptions) ([]container.Summary, error)
|
||||
containerPruneFunc func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error)
|
||||
containerPruneFunc func(ctx context.Context, options client.ContainerPruneOptions) (client.ContainerPruneResult, error)
|
||||
eventsFn func(context.Context, client.EventsListOptions) (<-chan events.Message, <-chan error)
|
||||
imageListFunc func(ctx context.Context, options client.ImageListOptions) ([]image.Summary, error)
|
||||
infoFunc func(ctx context.Context) (system.Info, error)
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
|
||||
networkPruneFunc func(ctx context.Context, pruneFilter client.Filters) (network.PruneReport, error)
|
||||
networkPruneFunc func(ctx context.Context, options client.NetworkPruneOptions) (client.NetworkPruneResult, error)
|
||||
nodeListFunc func(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error)
|
||||
serverVersion func(ctx context.Context) (types.Version, error)
|
||||
volumeListFunc func(ctx context.Context, options client.VolumeListOptions) (volume.ListResponse, error)
|
||||
@ -41,11 +41,11 @@ func (cli *fakeClient) ContainerList(ctx context.Context, options client.Contain
|
||||
return []container.Summary{}, nil
|
||||
}
|
||||
|
||||
func (cli *fakeClient) ContainersPrune(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
|
||||
func (cli *fakeClient) ContainersPrune(ctx context.Context, opts client.ContainerPruneOptions) (client.ContainerPruneResult, error) {
|
||||
if cli.containerPruneFunc != nil {
|
||||
return cli.containerPruneFunc(ctx, pruneFilters)
|
||||
return cli.containerPruneFunc(ctx, opts)
|
||||
}
|
||||
return container.PruneReport{}, nil
|
||||
return client.ContainerPruneResult{}, nil
|
||||
}
|
||||
|
||||
func (cli *fakeClient) Events(ctx context.Context, opts client.EventsListOptions) (<-chan events.Message, <-chan error) {
|
||||
@ -73,11 +73,11 @@ func (cli *fakeClient) NetworkList(ctx context.Context, options client.NetworkLi
|
||||
return []network.Summary{}, nil
|
||||
}
|
||||
|
||||
func (cli *fakeClient) NetworksPrune(ctx context.Context, pruneFilter client.Filters) (network.PruneReport, error) {
|
||||
func (cli *fakeClient) NetworksPrune(ctx context.Context, opts client.NetworkPruneOptions) (client.NetworkPruneResult, error) {
|
||||
if cli.networkPruneFunc != nil {
|
||||
return cli.networkPruneFunc(ctx, pruneFilter)
|
||||
return cli.networkPruneFunc(ctx, opts)
|
||||
}
|
||||
return network.PruneReport{}, nil
|
||||
return client.NetworkPruneResult{}, nil
|
||||
}
|
||||
|
||||
func (cli *fakeClient) NodeList(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error) {
|
||||
|
||||
@ -239,7 +239,7 @@ func nodeNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []str
|
||||
// pluginNames contacts the API to get a list of plugin names.
|
||||
// In case of an error, an empty list is returned.
|
||||
func pluginNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []string {
|
||||
list, err := dockerCLI.Client().PluginList(cmd.Context(), nil)
|
||||
list, err := dockerCLI.Client().PluginList(cmd.Context(), client.PluginListOptions{})
|
||||
if err != nil {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
@ -8,8 +8,6 @@ import (
|
||||
|
||||
"github.com/docker/cli/cli/config/configfile"
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@ -56,11 +54,11 @@ func TestSystemPrunePromptTermination(t *testing.T) {
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
containerPruneFunc: func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
|
||||
return container.PruneReport{}, errors.New("fakeClient containerPruneFunc should not be called")
|
||||
containerPruneFunc: func(context.Context, client.ContainerPruneOptions) (client.ContainerPruneResult, error) {
|
||||
return client.ContainerPruneResult{}, errors.New("fakeClient containerPruneFunc should not be called")
|
||||
},
|
||||
networkPruneFunc: func(ctx context.Context, pruneFilters client.Filters) (network.PruneReport, error) {
|
||||
return network.PruneReport{}, errors.New("fakeClient networkPruneFunc should not be called")
|
||||
networkPruneFunc: func(context.Context, client.NetworkPruneOptions) (client.NetworkPruneResult, error) {
|
||||
return client.NetworkPruneResult{}, errors.New("fakeClient networkPruneFunc should not be called")
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ type fakeClient struct {
|
||||
volumeInspectFunc func(volumeID string) (volume.Volume, error)
|
||||
volumeListFunc func(filter client.Filters) (volume.ListResponse, error)
|
||||
volumeRemoveFunc func(volumeID string, force bool) error
|
||||
volumePruneFunc func(filter client.Filters) (volume.PruneReport, error)
|
||||
volumePruneFunc func(opts client.VolumePruneOptions) (client.VolumePruneResult, error)
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumeCreate(_ context.Context, options volume.CreateOptions) (volume.Volume, error) {
|
||||
@ -37,11 +37,11 @@ func (c *fakeClient) VolumeList(_ context.Context, options client.VolumeListOpti
|
||||
return volume.ListResponse{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumesPrune(_ context.Context, filter client.Filters) (volume.PruneReport, error) {
|
||||
func (c *fakeClient) VolumesPrune(_ context.Context, opts client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
if c.volumePruneFunc != nil {
|
||||
return c.volumePruneFunc(filter)
|
||||
return c.volumePruneFunc(opts)
|
||||
}
|
||||
return volume.PruneReport{}, nil
|
||||
return client.VolumePruneResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumeRemove(_ context.Context, volumeID string, force bool) error {
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/docker/cli/internal/prompt"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -88,17 +89,19 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||
}
|
||||
}
|
||||
|
||||
report, err := dockerCli.Client().VolumesPrune(ctx, pruneFilters)
|
||||
res, err := dockerCli.Client().VolumesPrune(ctx, client.VolumePruneOptions{
|
||||
Filters: pruneFilters,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
if len(report.VolumesDeleted) > 0 {
|
||||
if len(res.Report.VolumesDeleted) > 0 {
|
||||
output = "Deleted Volumes:\n"
|
||||
for _, id := range report.VolumesDeleted {
|
||||
for _, id := range res.Report.VolumesDeleted {
|
||||
output += id + "\n"
|
||||
}
|
||||
spaceReclaimed = report.SpaceReclaimed
|
||||
spaceReclaimed = res.Report.SpaceReclaimed
|
||||
}
|
||||
|
||||
return spaceReclaimed, output, nil
|
||||
|
||||
@ -21,11 +21,11 @@ import (
|
||||
|
||||
func TestVolumePruneErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
flags map[string]string
|
||||
volumePruneFunc func(args client.Filters) (volume.PruneReport, error)
|
||||
expectedError string
|
||||
name string
|
||||
args []string
|
||||
flags map[string]string
|
||||
pruneFunc func(client.VolumePruneOptions) (client.VolumePruneResult, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "accepts no arguments",
|
||||
@ -37,8 +37,8 @@ func TestVolumePruneErrors(t *testing.T) {
|
||||
flags: map[string]string{
|
||||
"force": "true",
|
||||
},
|
||||
volumePruneFunc: func(args client.Filters) (volume.PruneReport, error) {
|
||||
return volume.PruneReport{}, errors.New("error pruning volumes")
|
||||
pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
return client.VolumePruneResult{}, errors.New("error pruning volumes")
|
||||
},
|
||||
expectedError: "error pruning volumes",
|
||||
},
|
||||
@ -55,7 +55,7 @@ func TestVolumePruneErrors(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cmd := newPruneCommand(
|
||||
test.NewFakeCli(&fakeClient{
|
||||
volumePruneFunc: tc.volumePruneFunc,
|
||||
volumePruneFunc: tc.pruneFunc,
|
||||
}),
|
||||
)
|
||||
cmd.SetArgs(tc.args)
|
||||
@ -71,40 +71,40 @@ func TestVolumePruneErrors(t *testing.T) {
|
||||
|
||||
func TestVolumePruneSuccess(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
input string
|
||||
volumePruneFunc func(args client.Filters) (volume.PruneReport, error)
|
||||
name string
|
||||
args []string
|
||||
input string
|
||||
pruneFunc func(client.VolumePruneOptions) (client.VolumePruneResult, error)
|
||||
}{
|
||||
{
|
||||
name: "all",
|
||||
args: []string{"--all"},
|
||||
input: "y",
|
||||
volumePruneFunc: func(pruneFilter client.Filters) (volume.PruneReport, error) {
|
||||
assert.Check(t, is.DeepEqual(pruneFilter["all"], map[string]bool{"true": true}))
|
||||
return volume.PruneReport{}, nil
|
||||
pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
assert.Check(t, is.DeepEqual(opts.Filters["all"], map[string]bool{"true": true}))
|
||||
return client.VolumePruneResult{}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "all-forced",
|
||||
args: []string{"--all", "--force"},
|
||||
volumePruneFunc: func(pruneFilter client.Filters) (volume.PruneReport, error) {
|
||||
return volume.PruneReport{}, nil
|
||||
pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
return client.VolumePruneResult{}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "label-filter",
|
||||
args: []string{"--filter", "label=foobar"},
|
||||
input: "y",
|
||||
volumePruneFunc: func(pruneFilter client.Filters) (volume.PruneReport, error) {
|
||||
assert.Check(t, is.DeepEqual(pruneFilter["label"], map[string]bool{"foobar": true}))
|
||||
return volume.PruneReport{}, nil
|
||||
pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
assert.Check(t, is.DeepEqual(opts.Filters["label"], map[string]bool{"foobar": true}))
|
||||
return client.VolumePruneResult{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{volumePruneFunc: tc.volumePruneFunc})
|
||||
cli := test.NewFakeCli(&fakeClient{volumePruneFunc: tc.pruneFunc})
|
||||
cmd := newPruneCommand(cli)
|
||||
if tc.input != "" {
|
||||
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(tc.input))))
|
||||
@ -121,7 +121,7 @@ func TestVolumePruneSuccess(t *testing.T) {
|
||||
func TestVolumePruneForce(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
volumePruneFunc func(args client.Filters) (volume.PruneReport, error)
|
||||
volumePruneFunc func(options client.VolumePruneOptions) (client.VolumePruneResult, error)
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
@ -180,12 +180,14 @@ func TestVolumePrunePromptNo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func simplePruneFunc(client.Filters) (volume.PruneReport, error) {
|
||||
return volume.PruneReport{
|
||||
VolumesDeleted: []string{
|
||||
"foo", "bar", "baz",
|
||||
func simplePruneFunc(options client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
return client.VolumePruneResult{
|
||||
Report: volume.PruneReport{
|
||||
VolumesDeleted: []string{
|
||||
"foo", "bar", "baz",
|
||||
},
|
||||
SpaceReclaimed: 2000,
|
||||
},
|
||||
SpaceReclaimed: 2000,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -194,8 +196,8 @@ func TestVolumePrunePromptTerminate(t *testing.T) {
|
||||
t.Cleanup(cancel)
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumePruneFunc: func(filter client.Filters) (volume.PruneReport, error) {
|
||||
return volume.PruneReport{}, errors.New("fakeClient volumePruneFunc should not be called")
|
||||
volumePruneFunc: func(options client.VolumePruneOptions) (client.VolumePruneResult, error) {
|
||||
return client.VolumePruneResult{}, errors.New("fakeClient volumePruneFunc should not be called")
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/completion"
|
||||
"github.com/moby/moby/api/types/volume"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@ -60,7 +61,7 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, volumeID, availabilit
|
||||
|
||||
return apiClient.VolumeUpdate(
|
||||
ctx, vol.ClusterVolume.ID, vol.ClusterVolume.Version,
|
||||
volume.UpdateOptions{
|
||||
client.VolumeUpdateOptions{
|
||||
Spec: &vol.ClusterVolume.Spec,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user