Skip to content

Commit

Permalink
Fix aggregateScanResults (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Oct 15, 2023
1 parent a737242 commit 05ddca5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scanpullrequest/scanpullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 32 additions & 0 deletions scanpullrequest/scanpullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 05ddca5

Please sign in to comment.