Skip to content

Commit 48b3ea1

Browse files
authored
Fixing search results (#863)
* Fixing search results * Adding additional search test * gofmt search_test
1 parent 6e7a20d commit 48b3ea1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cmd/krew/cmd/search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ type searchItem struct {
3838
type searchCorpus []searchItem
3939

4040
func (s searchCorpus) descriptions() []string {
41-
var res = make([]string, len(s))
41+
res := make([]string, 0, len(s))
4242
for _, corpus := range s {
4343
res = append(res, corpus.description)
4444
}
4545
return res
4646
}
4747

4848
func (s searchCorpus) names() []string {
49-
var res = make([]string, len(s))
49+
res := make([]string, 0, len(s))
5050
for _, corpus := range s {
5151
res = append(res, corpus.name)
5252
}

cmd/krew/cmd/search_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ func Test_searchByNameAndDesc(t *testing.T) {
5959
},
6060
expected: []string{"baz"},
6161
},
62+
{
63+
keyword: "",
64+
names: []string{"plugin1", "plugin2", "plugin3"}, // empty keyword, only names match
65+
descs: []string{
66+
"Description for plugin1",
67+
"Description for plugin2",
68+
"Description for plugin3",
69+
},
70+
expected: []string{"plugin1", "plugin2", "plugin3"},
71+
},
6272
}
6373

6474
for _, tp := range testPlugins {

0 commit comments

Comments
 (0)