Commit f2b63805 authored by Matt Butcher's avatar Matt Butcher

fix(helm): fix search bugs

This fixes three things:
- #741 output is wrong
- #743 nil pointer error because of unchecked error
- Printing "Chart:" string in output
parent 968901f9
...@@ -32,7 +32,6 @@ func search(cmd *cobra.Command, args []string) error { ...@@ -32,7 +32,6 @@ func search(cmd *cobra.Command, args []string) error {
return err return err
} }
if len(results) > 0 { if len(results) > 0 {
cmd.Println("Charts:")
for _, result := range results { for _, result := range results {
fmt.Println(result) fmt.Println(result)
} }
...@@ -68,11 +67,19 @@ func searchCacheForPattern(dir string, search string) ([]string, error) { ...@@ -68,11 +67,19 @@ func searchCacheForPattern(dir string, search string) ([]string, error) {
}) })
matches := []string{} matches := []string{}
for _, f := range fileList { for _, f := range fileList {
index, _ := repo.LoadIndexFile(f) index, err := repo.LoadIndexFile(f)
if err != nil {
return matches, fmt.Errorf("index %s corrupted: %s", f, err)
}
m := searchChartRefsForPattern(search, index.Entries) m := searchChartRefsForPattern(search, index.Entries)
repoName := strings.TrimSuffix(filepath.Base(f), "-index.yaml") repoName := strings.TrimSuffix(filepath.Base(f), "-index.yaml")
for _, c := range m { for _, c := range m {
matches = append(matches, repoName+"/"+c) // TODO: Is it possible for this file to be missing? Or to have
// an extension other than .tgz? Should the actual filename be in
// the YAML?
fname := filepath.Join(repoName, c+".tgz")
matches = append(matches, fname)
} }
} }
return matches, nil return matches, nil
......
...@@ -23,10 +23,10 @@ var searchTestCases = []searchTestCase{ ...@@ -23,10 +23,10 @@ var searchTestCases = []searchTestCase{
var searchCacheTestCases = []searchTestCase{ var searchCacheTestCases = []searchTestCase{
{"notthere", []string{}}, {"notthere", []string{}},
{"odd", []string{"foobar/oddness-1.2.3"}}, {"odd", []string{"foobar/oddness-1.2.3.tgz"}},
{"sumtin", []string{"local/alpine-1.0.0", "foobar/oddness-1.2.3"}}, {"sumtin", []string{"local/alpine-1.0.0.tgz", "foobar/oddness-1.2.3.tgz"}},
{"foobar", []string{"foobar/foobar-0.1.0"}}, {"foobar", []string{"foobar/foobar-0.1.0.tgz"}},
{"web", []string{"local/nginx-0.1.0"}}, {"web", []string{"local/nginx-0.1.0.tgz"}},
} }
func validateEntries(t *testing.T, in string, found []string, expected []string) { func validateEntries(t *testing.T, in string, found []string, expected []string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment