From 6040e5826235f4d8b30753aa83e112de7e0868f1 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 26 Sep 2024 17:23:51 +0200 Subject: [PATCH] complete info to recommendation --- bundle/render/render_text_output.go | 12 +++- bundle/render/render_text_output_test.go | 76 ++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/bundle/render/render_text_output.go b/bundle/render/render_text_output.go index 772781d7a..f005e5b47 100644 --- a/bundle/render/render_text_output.go +++ b/bundle/render/render_text_output.go @@ -111,9 +111,15 @@ func buildTrailer(diags diag.Diagnostics) string { if recommendations := len(diags.Filter(diag.Recommendation)); recommendations > 0 { parts = append(parts, color.BlueString(pluralize(recommendations, "recommendation", "recommendations"))) } - if len(parts) > 0 { - return fmt.Sprintf("Found %s", strings.Join(parts, " and ")) - } else { + switch { + case len(parts) >= 2: + first := strings.Join(parts[:len(parts)-1], ", ") + last := parts[len(parts)-1] + return fmt.Sprintf("Found %s and %s", first, last) + case len(parts) == 1: + return fmt.Sprintf("Found %s", parts[0]) + default: + // No diagnostics to print. return color.GreenString("Validation OK!") } } diff --git a/bundle/render/render_text_output_test.go b/bundle/render/render_text_output_test.go index 86321e0f1..8921f02f2 100644 --- a/bundle/render/render_text_output_test.go +++ b/bundle/render/render_text_output_test.go @@ -46,7 +46,7 @@ func TestRenderTextOutput(t *testing.T) { "Found 1 error\n", }, { - name: "nil bundle and 1 info", + name: "nil bundle and 1 recommendation", diags: diag.Diagnostics{ { Severity: diag.Recommendation, @@ -97,7 +97,7 @@ func TestRenderTextOutput(t *testing.T) { "Found 2 warnings\n", }, { - name: "bundle during 'load' and 2 errors, 1 warning and 1 info with details", + name: "bundle during 'load' and 2 errors, 1 warning and 1 recommendation with details", bundle: loadingBundle, diags: diag.Diagnostics{ diag.Diagnostic{ @@ -149,7 +149,73 @@ func TestRenderTextOutput(t *testing.T) { "Name: test-bundle\n" + "Target: test-target\n" + "\n" + - "Found 2 errors and 1 warning and 1 recommendation\n", + "Found 2 errors, 1 warning and 1 recommendation\n", + }, + { + name: "bundle during 'load' and 1 errors, 2 warning and 2 recommendations with details", + bundle: loadingBundle, + diags: diag.Diagnostics{ + diag.Diagnostic{ + Severity: diag.Error, + Summary: "error (1)", + Detail: "detail (1)", + Locations: []dyn.Location{{File: "foo.py", Line: 1, Column: 1}}, + }, + diag.Diagnostic{ + Severity: diag.Warning, + Summary: "warning (2)", + Detail: "detail (2)", + Locations: []dyn.Location{{File: "foo.py", Line: 2, Column: 1}}, + }, + diag.Diagnostic{ + Severity: diag.Warning, + Summary: "warning (3)", + Detail: "detail (3)", + Locations: []dyn.Location{{File: "foo.py", Line: 3, Column: 1}}, + }, + diag.Diagnostic{ + Severity: diag.Recommendation, + Summary: "recommendation (4)", + Detail: "detail (4)", + Locations: []dyn.Location{{File: "foo.py", Line: 4, Column: 1}}, + }, + diag.Diagnostic{ + Severity: diag.Recommendation, + Summary: "recommendation (5)", + Detail: "detail (5)", + Locations: []dyn.Location{{File: "foo.py", Line: 5, Column: 1}}, + }, + }, + opts: RenderOptions{RenderSummaryTable: true}, + expected: "Error: error (1)\n" + + " in foo.py:1:1\n" + + "\n" + + "detail (1)\n" + + "\n" + + "Warning: warning (2)\n" + + " in foo.py:2:1\n" + + "\n" + + "detail (2)\n" + + "\n" + + "Warning: warning (3)\n" + + " in foo.py:3:1\n" + + "\n" + + "detail (3)\n" + + "\n" + + "Recommendation: recommendation (4)\n" + + " in foo.py:4:1\n" + + "\n" + + "detail (4)\n" + + "\n" + + "Recommendation: recommendation (5)\n" + + " in foo.py:5:1\n" + + "\n" + + "detail (5)\n" + + "\n" + + "Name: test-bundle\n" + + "Target: test-target\n" + + "\n" + + "Found 1 error, 2 warnings and 2 recommendations\n", }, { name: "bundle during 'init'", @@ -182,7 +248,7 @@ func TestRenderTextOutput(t *testing.T) { "Validation OK!\n", }, { - name: "nil bundle without summary with 1 error, 1 warning and 1 info", + name: "nil bundle without summary with 1 error, 1 warning and 1 recommendation", bundle: nil, diags: diag.Diagnostics{ diag.Diagnostic{ @@ -340,7 +406,7 @@ func TestRenderDiagnostics(t *testing.T) { "'name' is required\n\n", }, { - name: "info with multiple paths and locations", + name: "recommendation with multiple paths and locations", diags: diag.Diagnostics{ { Severity: diag.Recommendation,