From 05ddca536772c70f4894ac4408983bca2b7fc592 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni <50792403+omerzi@users.noreply.github.com> Date: Sun, 15 Oct 2023 13:13:49 +0300 Subject: [PATCH] Fix aggregateScanResults (#543) --- scanpullrequest/scanpullrequest.go | 2 ++ scanpullrequest/scanpullrequest_test.go | 32 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/scanpullrequest/scanpullrequest.go b/scanpullrequest/scanpullrequest.go index 98d19c5f6..0dbff7131 100644 --- a/scanpullrequest/scanpullrequest.go +++ b/scanpullrequest/scanpullrequest.go @@ -376,10 +376,12 @@ func aggregateScanResults(scanResults []services.ScanResponse) services.ScanResp aggregateResults := services.ScanResponse{ Violations: []services.Violation{}, Vulnerabilities: []services.Vulnerability{}, + Licenses: []services.License{}, } for _, scanResult := range scanResults { aggregateResults.Violations = append(aggregateResults.Violations, scanResult.Violations...) aggregateResults.Vulnerabilities = append(aggregateResults.Vulnerabilities, scanResult.Vulnerabilities...) + aggregateResults.Licenses = append(aggregateResults.Licenses, scanResult.Licenses...) } return aggregateResults } diff --git a/scanpullrequest/scanpullrequest_test.go b/scanpullrequest/scanpullrequest_test.go index 6cf837db6..d5e567910 100644 --- a/scanpullrequest/scanpullrequest_test.go +++ b/scanpullrequest/scanpullrequest_test.go @@ -1195,6 +1195,38 @@ func TestDeletePreviousPullRequestReviewMessages(t *testing.T) { } } +func TestAggregateScanResults(t *testing.T) { + scanResult1 := services.ScanResponse{ + Violations: []services.Violation{{IssueId: "Violation 1"}}, + Vulnerabilities: []services.Vulnerability{{IssueId: "Vulnerability 1"}}, + Licenses: []services.License{{Name: "License 1"}}, + } + + scanResult2 := services.ScanResponse{ + Violations: []services.Violation{{IssueId: "Violation 2"}}, + Vulnerabilities: []services.Vulnerability{{IssueId: "Vulnerability 2"}}, + Licenses: []services.License{{Name: "License 2"}}, + } + + aggregateResult := aggregateScanResults([]services.ScanResponse{scanResult1, scanResult2}) + expectedResult := services.ScanResponse{ + Violations: []services.Violation{ + {IssueId: "Violation 1"}, + {IssueId: "Violation 2"}, + }, + Vulnerabilities: []services.Vulnerability{ + {IssueId: "Vulnerability 1"}, + {IssueId: "Vulnerability 2"}, + }, + Licenses: []services.License{ + {Name: "License 1"}, + {Name: "License 2"}, + }, + } + + assert.Equal(t, expectedResult, aggregateResult) +} + // Set new logger with output redirection to a null logger. This is useful for negative tests. // Caller is responsible to set the old log back. func redirectLogOutputToNil() (previousLog log.Log) {