Compare commits

..

1 Commits

Author SHA1 Message Date
Harald Albers e018b7ad75
Merge 8ae6ad6256 into 8a7c5ae68f 2024-10-18 09:56:02 -07:00
4 changed files with 6 additions and 59 deletions

View File

@ -19,7 +19,6 @@ type fakeClient struct {
eventsFn func(context.Context, events.ListOptions) (<-chan events.Message, <-chan error)
containerPruneFunc func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
networkPruneFunc func(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
containerListFunc func(context.Context, container.ListOptions) ([]container.Summary, error)
}
func (cli *fakeClient) ServerVersion(ctx context.Context) (types.Version, error) {
@ -47,10 +46,3 @@ func (cli *fakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Ar
}
return network.PruneReport{}, nil
}
func (cli *fakeClient) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error) {
if cli.containerListFunc != nil {
return cli.containerListFunc(ctx, options)
}
return []container.Summary{}, nil
}

View File

@ -154,7 +154,7 @@ func eventTypeNames() []string {
// The list is derived from eventActions.
// Actions that are not suitable for usage in completions are removed.
func validEventNames() []string {
names := []string{}
var names []string
for _, eventAction := range eventActions {
if strings.Contains(string(eventAction), " ") {
continue
@ -191,7 +191,7 @@ func imageNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []st
if err != nil {
return []string{}
}
names := []string{}
var names []string
for _, img := range list {
names = append(names, img.RepoTags...)
}
@ -205,7 +205,7 @@ func networkNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []
if err != nil {
return []string{}
}
names := []string{}
var names []string
for _, nw := range list {
names = append(names, nw.Name)
}
@ -219,7 +219,7 @@ func nodeNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []str
if err != nil {
return []string{}
}
names := []string{}
var names []string
for _, node := range list {
names = append(names, node.Description.Hostname)
}
@ -233,7 +233,7 @@ func volumeNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []s
if err != nil {
return []string{}
}
names := []string{}
var names []string
for _, v := range list.Volumes {
names = append(names, v.Name)
}

View File

@ -1,45 +0,0 @@
package system
import (
"context"
"errors"
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types/container"
"github.com/spf13/cobra"
"gotest.tools/v3/assert"
)
// Successful completion lists all container names, prefixed with "container=".
// Filtering the completions by the current word is delegated to the completion script.
func TestCompleteEventFilterContainer(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ context.Context, _ container.ListOptions) ([]container.Summary, error) {
return []container.Summary{
*builders.Container("foo"),
*builders.Container("bar"),
}, nil
},
})
completions, directive := completeFilters(cli)(NewEventsCommand(cli), nil, "container=")
assert.DeepEqual(t, completions, []string{"container=foo", "container=bar"})
assert.Equal(t, directive, cobra.ShellCompDirectiveNoFileComp)
}
// In case of API errors, no completions are returned.
func TestCompleteEventFilterContainerAPIError(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(_ context.Context, _ container.ListOptions) ([]container.Summary, error) {
return nil, errors.New("API error")
},
})
completions, directive := completeFilters(cli)(NewEventsCommand(cli), nil, "container=")
assert.DeepEqual(t, completions, []string{})
assert.Equal(t, directive, cobra.ShellCompDirectiveNoFileComp)
}

View File

@ -5081,7 +5081,7 @@ _docker_system_events() {
return
;;
daemon)
local name=$(__docker_q info --format '{{.Info.Name}} {{.Info.ID}}')
local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
return
;;