Skip to content

Commit

Permalink
refactor: show legend after table
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Jan 29, 2025
1 parent 5f13964 commit 7f863b9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
12 changes: 8 additions & 4 deletions pkg/report/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ func (tw Writer) renderSummary(report types.Report) error {
}

// Fprintln has a bug
if err := tml.Fprintf(tw.Output, "\n<underline><bold>Report Summary</bold></underline>\n\n"+
"Legend:\n"+
"- '-': Not scanned\n"+
"- '0': Clean (no security findings detected)\n"); err != nil {
if err := tml.Fprintf(tw.Output, "\n<underline><bold>Report Summary</bold></underline>\n\n"); err != nil {
return err
}

Expand Down Expand Up @@ -149,6 +146,13 @@ func (tw Writer) renderSummary(report types.Report) error {
t.AddRows(rows)
}
t.Render()

// Show legend
if err := tml.Fprintf(tw.Output, "Legend:\n"+
"- '-': Not scanned\n"+
"- '0': Clean (no security findings detected)\n\n"); err != nil {
return err
}
return nil
}

Expand Down
21 changes: 12 additions & 9 deletions pkg/report/table/table_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ func Test_renderSummary(t *testing.T) {
want: `
Report Summary
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
┌───────────────────────────────────┬────────────┬─────────────────┬───────────────────┬─────────┬──────────┐
│ Target │ Type │ Vulnerabilities │ Misconfigurations │ Secrets │ Licenses │
├───────────────────────────────────┼────────────┼─────────────────┼───────────────────┼─────────┼──────────┤
Expand All @@ -219,6 +216,10 @@ Legend:
├───────────────────────────────────┼────────────┼─────────────────┼───────────────────┼─────────┼──────────┤
│ Loose File License(s) │ - │ - │ - │ - │ 1 │
└───────────────────────────────────┴────────────┴─────────────────┴───────────────────┴─────────┴──────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
`,
},
{
Expand All @@ -235,9 +236,6 @@ Legend:
want: `
Report Summary
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
┌───────────────────────────────────┬────────┬─────────────────┐
│ Target │ Type │ Vulnerabilities │
├───────────────────────────────────┼────────┼─────────────────┤
Expand All @@ -247,6 +245,10 @@ Legend:
├───────────────────────────────────┼────────┼─────────────────┤
│ app/jackson-databind-2.13.4.1.jar │ jar │ 2 │
└───────────────────────────────────┴────────┴─────────────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
`,
},
{
Expand All @@ -264,16 +266,17 @@ Legend:
want: `
Report Summary
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
┌──────────────────┬──────┬─────────────────┬─────────┐
│ Target │ Type │ Vulnerabilities │ Secrets │
├──────────────────┼──────┼─────────────────┼─────────┤
│ requirements.txt │ pip │ 0 │ - │
├──────────────────┼──────┼─────────────────┼─────────┤
│ requirements.txt │ text │ - │ 1 │
└──────────────────┴──────┴─────────────────┴─────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
`,
},
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/report/table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ func TestWriter_Write(t *testing.T) {
wantOutput: `
Report Summary
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
┌──────────┬──────┬─────────────────┐
│ Target │ Type │ Vulnerabilities │
├──────────┼──────┼─────────────────┤
│ test.jar │ jar │ 1 │
└──────────┴──────┴─────────────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
test (jar)
==========
Expand Down Expand Up @@ -109,14 +110,15 @@ Total: 1 (MEDIUM: 0, HIGH: 1)
wantOutput: `
Report Summary
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
┌──────────┬──────┬─────────────────┐
│ Target │ Type │ Vulnerabilities │
├──────────┼──────┼─────────────────┤
│ test.jar │ jar │ 0 │
└──────────┴──────┴─────────────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
`,
},
{
Expand Down

0 comments on commit 7f863b9

Please sign in to comment.