Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(general): remove duplicated reports #3495

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions checkov/common/runners/runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def _merge_reports(self, reports: Iterable[Report | list[Report]]) -> list[Repor
merge_reports(self._check_type_to_report_map[sub_report.check_type], sub_report)
else:
self._check_type_to_report_map[sub_report.check_type] = sub_report

merged_reports.append(sub_report)
merged_reports.append(sub_report)

return merged_reports

Expand Down
27 changes: 27 additions & 0 deletions tests/common/runner_registry/test_runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from checkov.cloudformation.runner import Runner as cfn_runner
from checkov.common.bridgecrew.check_type import CheckType
from checkov.common.bridgecrew.code_categories import CodeCategoryMapping
from checkov.common.output.report import Report
from checkov.common.runners.runner_registry import RunnerRegistry
from checkov.common.util.banner import banner
from checkov.kubernetes.runner import Runner as k8_runner
Expand Down Expand Up @@ -238,6 +239,32 @@ def test_extract_git_info_from_account_id(self):
self.assertEqual(expected_git_repo, result_git_repo)
self.assertEqual(expected_git_org, result_git_org)

def test_merge_reports(self):
# given
runner_registry = RunnerRegistry(banner, RunnerFilter(), *DEFAULT_RUNNERS)
reports = [
[
Report(check_type=CheckType.TERRAFORM),
Report(check_type=CheckType.SCA_IMAGE),
],
Report(check_type=CheckType.CLOUDFORMATION),
Report(check_type=CheckType.SCA_IMAGE),
]

# when
merged_reports = runner_registry._merge_reports(reports=reports)

# then
merged_report_check_types = [
report.check_type
for report in merged_reports
]
self.assertCountEqual(merged_report_check_types,[
CheckType.TERRAFORM,
CheckType.CLOUDFORMATION,
CheckType.SCA_IMAGE,
])


def test_non_compact_json_output(capsys):
# given
Expand Down