feat(): fix failing test

pull/6096/head^2
Art Begolli 6 years ago
parent 9672000bfb
commit bdbc88215c

@ -166,10 +166,12 @@ func (s *searchCmd) formatSearchResults(res []*search.Result, colWidth uint) str
} }
func (s *searchCmd) formatSearchResultsJson(res []*search.Result, colWidth uint) (string, error) { func (s *searchCmd) formatSearchResultsJson(res []*search.Result, colWidth uint) (string, error) {
var resultJson []ResultEntry
if len(res) == 0 { if len(res) == 0 {
return "No results found", nil return "No results found", nil
} }
resultJson := []ResultEntry{}
for _, r := range res { for _, r := range res {
resultRow := ResultEntry{ resultRow := ResultEntry{
Name: r.Name, Name: r.Name,
@ -179,12 +181,12 @@ func (s *searchCmd) formatSearchResultsJson(res []*search.Result, colWidth uint)
} }
resultJson = append(resultJson, resultRow) resultJson = append(resultJson, resultRow)
} }
json, err := json.MarshalIndent(Results{SearchResults: resultJson}, "", " ") jsonSearchResults, err := json.MarshalIndent(Results{SearchResults: resultJson}, "", " ")
if err != nil { if err != nil {
return "", err return "", err
} }
return string(json), nil return string(jsonSearchResults), nil
} }
func (s *searchCmd) buildIndex() (*search.Index, error) { func (s *searchCmd) buildIndex() (*search.Index, error) {

@ -85,10 +85,10 @@ func TestSearchCmd(t *testing.T) {
err: true, err: true,
}, },
{ {
name: "search for 'alpine', expect two matches in json", name: "search for 'alpine', expect two matches in json",
args: []string{"alpine"}, args: []string{"alpine"},
flags: []string{"--output", "json"}, flags: []string{"--output", "json"},
expected: "[\n {\n \"name\": \"testing/alpine\",\n \"chartVersion\": \"0.2.0\",\n \"appVersion\": \"2.3.4\",\n \"description\": \"Deploy a basic Alpine Linux pod\"\n }\n]\n", expected: "{\n \"searchResults\": \\[\n {\n \"name\": \"testing/alpine\",\n \"chartVersion\": \"0.2.0\",\n \"appVersion\": \"2.3.4\",\n \"description\": \"Deploy a basic Alpine Linux pod\"\n }\n \\]\n}",
}, },
} }

Loading…
Cancel
Save