Skip to content

Commit

Permalink
Fixing search results (#863)
Browse files Browse the repository at this point in the history
* Fixing search results

* Adding additional search test

* gofmt search_test
  • Loading branch information
wallentx authored Oct 8, 2024
1 parent 6e7a20d commit 48b3ea1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/krew/cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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)
}
return res
}

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)
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/krew/cmd/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 48b3ea1

Please sign in to comment.