complete info to recommendation

This commit is contained in:
Shreyas Goenka 2024-09-26 17:23:51 +02:00
parent d9cf582287
commit 6040e58262
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 80 additions and 8 deletions

View File

@ -111,9 +111,15 @@ func buildTrailer(diags diag.Diagnostics) string {
if recommendations := len(diags.Filter(diag.Recommendation)); recommendations > 0 { if recommendations := len(diags.Filter(diag.Recommendation)); recommendations > 0 {
parts = append(parts, color.BlueString(pluralize(recommendations, "recommendation", "recommendations"))) parts = append(parts, color.BlueString(pluralize(recommendations, "recommendation", "recommendations")))
} }
if len(parts) > 0 { switch {
return fmt.Sprintf("Found %s", strings.Join(parts, " and ")) case len(parts) >= 2:
} else { 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!") return color.GreenString("Validation OK!")
} }
} }

View File

@ -46,7 +46,7 @@ func TestRenderTextOutput(t *testing.T) {
"Found 1 error\n", "Found 1 error\n",
}, },
{ {
name: "nil bundle and 1 info", name: "nil bundle and 1 recommendation",
diags: diag.Diagnostics{ diags: diag.Diagnostics{
{ {
Severity: diag.Recommendation, Severity: diag.Recommendation,
@ -97,7 +97,7 @@ func TestRenderTextOutput(t *testing.T) {
"Found 2 warnings\n", "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, bundle: loadingBundle,
diags: diag.Diagnostics{ diags: diag.Diagnostics{
diag.Diagnostic{ diag.Diagnostic{
@ -149,7 +149,73 @@ func TestRenderTextOutput(t *testing.T) {
"Name: test-bundle\n" + "Name: test-bundle\n" +
"Target: test-target\n" + "Target: test-target\n" +
"\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'", name: "bundle during 'init'",
@ -182,7 +248,7 @@ func TestRenderTextOutput(t *testing.T) {
"Validation OK!\n", "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, bundle: nil,
diags: diag.Diagnostics{ diags: diag.Diagnostics{
diag.Diagnostic{ diag.Diagnostic{
@ -340,7 +406,7 @@ func TestRenderDiagnostics(t *testing.T) {
"'name' is required\n\n", "'name' is required\n\n",
}, },
{ {
name: "info with multiple paths and locations", name: "recommendation with multiple paths and locations",
diags: diag.Diagnostics{ diags: diag.Diagnostics{
{ {
Severity: diag.Recommendation, Severity: diag.Recommendation,