diff --git a/cmd/krew/cmd/search.go b/cmd/krew/cmd/search.go index d4b10a91..12a4dfba 100644 --- a/cmd/krew/cmd/search.go +++ b/cmd/krew/cmd/search.go @@ -38,7 +38,7 @@ type searchItem struct { type searchCorpus []searchItem func (s searchCorpus) descriptions() []string { - var res = make([]string, len(s)) + res := make([]string, 0, len(s)) for _, corpus := range s { res = append(res, corpus.description) } @@ -46,7 +46,7 @@ func (s searchCorpus) descriptions() []string { } func (s searchCorpus) names() []string { - var res = make([]string, len(s)) + res := make([]string, 0, len(s)) for _, corpus := range s { res = append(res, corpus.name) } diff --git a/cmd/krew/cmd/search_test.go b/cmd/krew/cmd/search_test.go index 00797c92..bb4a3c7b 100644 --- a/cmd/krew/cmd/search_test.go +++ b/cmd/krew/cmd/search_test.go @@ -59,6 +59,16 @@ func Test_searchByNameAndDesc(t *testing.T) { }, expected: []string{"baz"}, }, + { + keyword: "", + names: []string{"plugin1", "plugin2", "plugin3"}, // empty keyword, only names match + descs: []string{ + "Description for plugin1", + "Description for plugin2", + "Description for plugin3", + }, + expected: []string{"plugin1", "plugin2", "plugin3"}, + }, } for _, tp := range testPlugins {