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/builder/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package builder
import (
"context"

"github.com/moby/moby/api/types/build"
"github.com/moby/moby/client"
)

type fakeClient struct {
client.Client
builderPruneFunc func(ctx context.Context, opts client.BuildCachePruneOptions) (*build.CachePruneReport, error)
builderPruneFunc func(ctx context.Context, opts client.BuildCachePruneOptions) (client.BuildCachePruneResult, error)
}

func (c *fakeClient) BuildCachePrune(ctx context.Context, opts client.BuildCachePruneOptions) (*build.CachePruneReport, error) {
func (c *fakeClient) BuildCachePrune(ctx context.Context, opts client.BuildCachePruneOptions) (client.BuildCachePruneResult, error) {
if c.builderPruneFunc != nil {
return c.builderPruneFunc(ctx, opts)
}
return nil, nil
return client.BuildCachePruneResult{}, nil
}
7 changes: 3 additions & 4 deletions cli/command/builder/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ const (
)

func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
pruneFilters := options.filter.Value()
pruneFilters = command.PruneFilters(dockerCli, pruneFilters)
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())

warning := normalWarning
if options.all {
Expand All @@ -87,15 +86,15 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
}
}

report, err := dockerCli.Client().BuildCachePrune(ctx, client.BuildCachePruneOptions{
resp, err := dockerCli.Client().BuildCachePrune(ctx, client.BuildCachePruneOptions{
All: options.all,
ReservedSpace: options.reservedSpace.Value(),
Filters: pruneFilters,
})
if err != nil {
return 0, "", err
}

report := resp.Report
if len(report.CachesDeleted) > 0 {
var sb strings.Builder
sb.WriteString("Deleted build cache objects:\n")
Expand Down
5 changes: 2 additions & 3 deletions cli/command/builder/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/docker/cli/internal/test"
"github.com/moby/moby/api/types/build"
"github.com/moby/moby/client"
)

Expand All @@ -16,8 +15,8 @@ func TestBuilderPromptTermination(t *testing.T) {
t.Cleanup(cancel)

cli := test.NewFakeCli(&fakeClient{
builderPruneFunc: func(ctx context.Context, opts client.BuildCachePruneOptions) (*build.CachePruneReport, error) {
return nil, errors.New("fakeClient builderPruneFunc should not be called")
builderPruneFunc: func(ctx context.Context, opts client.BuildCachePruneOptions) (client.BuildCachePruneResult, error) {
return client.BuildCachePruneResult{}, errors.New("fakeClient builderPruneFunc should not be called")
},
})
cmd := newPruneCommand(cli)
Expand Down
8 changes: 3 additions & 5 deletions cli/command/completion/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"sort"
"testing"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/volume"
Expand All @@ -33,7 +31,7 @@ type fakeClient struct {
containerListFunc func(options client.ContainerListOptions) ([]container.Summary, error)
imageListFunc func(options client.ImageListOptions) ([]image.Summary, error)
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
volumeListFunc func(filter filters.Args) (volume.ListResponse, error)
volumeListFunc func(filter client.Filters) (volume.ListResponse, error)
}

func (c *fakeClient) ContainerList(_ context.Context, options client.ContainerListOptions) ([]container.Summary, error) {
Expand Down Expand Up @@ -156,7 +154,7 @@ func TestCompleteContainerNames(t *testing.T) {
}
comp := ContainerNames(fakeCLI{&fakeClient{
containerListFunc: func(opts client.ContainerListOptions) ([]container.Summary, error) {
assert.Check(t, is.DeepEqual(opts, tc.expOpts, cmpopts.IgnoreUnexported(client.ContainerListOptions{}, filters.Args{})))
assert.Check(t, is.DeepEqual(opts, tc.expOpts))
if tc.expDirective == cobra.ShellCompDirectiveError {
return nil, errors.New("some error occurred")
}
Expand Down Expand Up @@ -339,7 +337,7 @@ func TestCompleteVolumeNames(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
comp := VolumeNames(fakeCLI{&fakeClient{
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
volumeListFunc: func(filter client.Filters) (volume.ListResponse, error) {
if tc.expDirective == cobra.ShellCompDirectiveError {
return volume.ListResponse{}, errors.New("some error occurred")
}
Expand Down
5 changes: 2 additions & 3 deletions cli/command/config/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
)

Expand Down Expand Up @@ -133,8 +132,8 @@ func TestConfigListWithFormat(t *testing.T) {
func TestConfigListWithFilter(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]))
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
assert.Check(t, options.Filters["name"]["foo"])
assert.Check(t, options.Filters["label"]["lbl1=Label-bar"])
return []swarm.Config{
*builders.Config(builders.ConfigID("ID-foo"),
builders.ConfigName("foo"),
Expand Down
5 changes: 2 additions & 3 deletions cli/command/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"

"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/system"
"github.com/moby/moby/client"
Expand Down Expand Up @@ -36,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 filters.Args) (container.PruneReport, error)
containerPruneFunc func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, 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
Expand Down Expand Up @@ -172,7 +171,7 @@ func (f *fakeClient) ContainerKill(ctx context.Context, containerID, signal stri
return nil
}

func (f *fakeClient) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) {
func (f *fakeClient) ContainersPrune(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
if f.containerPruneFunc != nil {
return f.containerPruneFunc(ctx, pruneFilters)
}
Expand Down
62 changes: 21 additions & 41 deletions cli/command/container/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
expectedAll bool
expectedSize bool
expectedLimit int
expectedFilters map[string]string
expectedFilters client.Filters
}{
{
psOpts: &psOptions{
Expand All @@ -35,13 +35,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
last: 5,
filter: filters,
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: map[string]string{
"foo": "bar",
"baz": "foo",
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
},
{
psOpts: &psOptions{
Expand All @@ -50,10 +47,9 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
last: -1,
nLatest: true,
},
expectedAll: true,
expectedSize: true,
expectedLimit: 1,
expectedFilters: make(map[string]string),
expectedAll: true,
expectedSize: true,
expectedLimit: 1,
},
{
psOpts: &psOptions{
Expand All @@ -64,13 +60,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
// With .Size, size should be true
format: "{{.Size}}",
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: map[string]string{
"foo": "bar",
"baz": "foo",
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
},
{
psOpts: &psOptions{
Expand All @@ -81,13 +74,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
// With .Size, size should be true
format: "{{.Size}} {{.CreatedAt}} {{upper .Networks}}",
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: map[string]string{
"foo": "bar",
"baz": "foo",
},
expectedAll: true,
expectedSize: true,
expectedLimit: 5,
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
},
{
psOpts: &psOptions{
Expand All @@ -98,13 +88,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
// Without .Size, size should be false
format: "{{.CreatedAt}} {{.Networks}}",
},
expectedAll: true,
expectedSize: false,
expectedLimit: 5,
expectedFilters: map[string]string{
"foo": "bar",
"baz": "foo",
},
expectedAll: true,
expectedSize: false,
expectedLimit: 5,
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
},
}

Expand All @@ -115,14 +102,7 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
assert.Check(t, is.Equal(c.expectedAll, options.All))
assert.Check(t, is.Equal(c.expectedSize, options.Size))
assert.Check(t, is.Equal(c.expectedLimit, options.Limit))
assert.Check(t, is.Equal(len(c.expectedFilters), options.Filters.Len()))

for k, v := range c.expectedFilters {
f := options.Filters
if !f.ExactMatch(k, v) {
t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k))
}
}
assert.Check(t, is.DeepEqual(c.expectedFilters, options.Filters))
}
}

Expand Down
Loading
Loading