Address code review feedback: nil check and trailing whitespace

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-03 16:46:11 +00:00
parent 6b80b85555
commit 1dd6d7a1b3
3 changed files with 19 additions and 10 deletions

View File

@@ -123,7 +123,7 @@ func printConfigurationsScanning(opaSessionObj *cautils.OPASessionObj, imageScan
// Convert to PostureReportWithSeverity to add severity field to controls
finalizedReport := FinalizeResults(opaSessionObj)
reportWithSeverity := ConvertToPostureReportWithSeverity(finalizedReport)
r, err := json.Marshal(reportWithSeverity)
_, err = jp.writer.Write(r)

View File

@@ -251,22 +251,22 @@ func TestEnrichControlsWithSeverity(t *testing.T) {
func TestConvertToPostureReportWithSeverity(t *testing.T) {
// Create a mock PostureReport with controls having different severity levels
mockReport := reportsummary.MockSummaryDetails()
// Get the controls from mock data
controls := mockReport.Controls
// Create a minimal PostureReport
report := &reporthandlingv2.PostureReport{
SummaryDetails: *mockReport,
}
// Convert to PostureReportWithSeverity
reportWithSeverity := ConvertToPostureReportWithSeverity(report)
// Verify controls have severity field
assert.NotNil(t, reportWithSeverity)
assert.NotNil(t, reportWithSeverity.SummaryDetails.Controls)
// Verify each control in the original report has a corresponding enriched control with severity
for controlID, control := range controls {
enrichedControl, exists := reportWithSeverity.SummaryDetails.Controls[controlID]
@@ -277,6 +277,12 @@ func TestConvertToPostureReportWithSeverity(t *testing.T) {
}
}
func TestConvertToPostureReportWithSeverityNilCheck(t *testing.T) {
// Test that nil report returns nil
result := ConvertToPostureReportWithSeverity(nil)
assert.Nil(t, result, "Converting nil report should return nil")
}
func TestEnrichResultsWithSeverity(t *testing.T) {
// Create mock control summaries
controlSummaries := reportsummary.ControlSummaries{
@@ -291,7 +297,7 @@ func TestEnrichResultsWithSeverity(t *testing.T) {
ScoreFactor: 6.0,
},
}
// Create mock results with associated controls
results := []resourcesresults.Result{
{
@@ -317,10 +323,10 @@ func TestEnrichResultsWithSeverity(t *testing.T) {
},
},
}
// Enrich results with severity
enrichedResults := enrichResultsWithSeverity(results, controlSummaries)
// Verify results structure
assert.Equal(t, 2, len(enrichedResults))

View File

@@ -103,9 +103,12 @@ func enrichResultsWithSeverity(results []resourcesresults.Result, controlSummari
// ConvertToPostureReportWithSeverity converts PostureReport to PostureReportWithSeverity
func ConvertToPostureReportWithSeverity(report *reporthandlingv2.PostureReport) *PostureReportWithSeverity {
if report == nil {
return nil
}
enrichedControls := enrichControlsWithSeverity(report.SummaryDetails.Controls)
enrichedResults := enrichResultsWithSeverity(report.Results, report.SummaryDetails.Controls)
return &PostureReportWithSeverity{
ReportGenerationTime: report.ReportGenerationTime.Format("2006-01-02T15:04:05Z07:00"),
ClusterAPIServerInfo: report.ClusterAPIServerInfo,