Skip to content

Commit c4689c1

Browse files
authored
[CRAVEX] SCA Integrations: Generic (#1841)
* Refactor the SCA test module to simplify addition of new tools #1726 Signed-off-by: tdruez <tdruez@nexb.com> * Use benchmark.compare_purls to assert the SBOM PURLs #1726 Signed-off-by: tdruez <tdruez@nexb.com> --------- Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 3d0e1bd commit c4689c1

File tree

2 files changed

+373
-136
lines changed

2 files changed

+373
-136
lines changed

scanpipe/pipes/benchmark.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ def get_expected_purls(project):
4949
return sorted(set(expected_purls))
5050

5151

52+
def get_unique_project_purls(project):
53+
"""
54+
Return the sorted list of unique Package URLs (PURLs) discovered in the project.
55+
56+
Extracts the ``purl`` field from all discovered packages, removes duplicates,
57+
and sorts the result to provide a deterministic list of project PURLs.
58+
"""
59+
project_packages = project.discoveredpackages.only_package_url_fields()
60+
sorted_unique_purls = sorted({package.purl for package in project_packages})
61+
return sorted_unique_purls
62+
63+
5264
def compare_purls(project, expected_purls):
5365
"""
5466
Compare discovered project PURLs against the expected PURLs.
@@ -57,10 +69,10 @@ def compare_purls(project, expected_purls):
5769
- Lines starting with '-' are missing from the project.
5870
- Lines starting with '+' are unexpected in the project.
5971
"""
60-
project_packages = project.discoveredpackages.only_package_url_fields()
61-
sorted_unique_purls = sorted({package.purl for package in project_packages})
72+
sorted_project_purls = get_unique_project_purls(project)
73+
print(sorted_project_purls)
6274

63-
diff_result = difflib.ndiff(sorted_unique_purls, expected_purls)
75+
diff_result = difflib.ndiff(sorted_project_purls, expected_purls)
6476

6577
# Keep only lines that are diffs (- or +)
6678
filtered_diff = [line for line in diff_result if line.startswith(("-", "+"))]

0 commit comments

Comments
 (0)