From 4ad5a25f9508615ee86eb4a093ab72dad1d3236f Mon Sep 17 00:00:00 2001 From: wallentx Date: Mon, 30 Sep 2024 13:57:10 -0500 Subject: [PATCH 1/3] Fixing search results --- cmd/krew/cmd/search.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) } From fb297a4038b4242947835a72baa19b18ef25b0e3 Mon Sep 17 00:00:00 2001 From: wallentx Date: Tue, 1 Oct 2024 04:45:56 -0500 Subject: [PATCH 2/3] Adding additional search test --- cmd/krew/cmd/search_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/krew/cmd/search_test.go b/cmd/krew/cmd/search_test.go index 00797c92..71e2aab5 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 { From ccc96313b70ddcd9e58985d42d3af8b185f2265b Mon Sep 17 00:00:00 2001 From: wallentx Date: Tue, 1 Oct 2024 04:49:11 -0500 Subject: [PATCH 3/3] gofmt search_test --- cmd/krew/cmd/search_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/krew/cmd/search_test.go b/cmd/krew/cmd/search_test.go index 71e2aab5..bb4a3c7b 100644 --- a/cmd/krew/cmd/search_test.go +++ b/cmd/krew/cmd/search_test.go @@ -59,16 +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"}, - }, + { + 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 {