Skip to content

Commit 39e8344

Browse files
committed
Refactor the ScanPipeIntegrationsBaseTest for re-usability
Signed-off-by: tdruez <[email protected]>
1 parent c5938f4 commit 39e8344

9 files changed

+17
-15
lines changed

scanpipe/pipes/benchmark.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ def compare_purls(project, expected_purls):
7070
- Lines starting with '+' are unexpected in the project.
7171
"""
7272
sorted_project_purls = get_unique_project_purls(project)
73-
print(sorted_project_purls)
74-
7573
diff_result = difflib.ndiff(sorted_project_purls, expected_purls)
7674

7775
# Keep only lines that are diffs (- or +)

scanpipe/tests/test_sca_integrations.py renamed to scanpipe/tests/test_integrations_sca_tools.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
--output trivy-alpine-3.17-sbom.json alpine:3.17.0
3636
3737
2. Save the SBOM file under:
38-
tests/data/sca-integrations/
38+
tests/data/integrations-sca/
3939
40-
3. Add expected counts for that SBOM to ``SCA_INTEGRATIONS_TEST_DATA`` below.
40+
3. Add expected counts for that SBOM to `TEST_DATA`` below.
4141
4242
Example:
4343
"trivy-alpine-3.17-sbom.json": {
@@ -55,7 +55,7 @@
5555
5656
4. Run the test suite:
5757
58-
./manage.py test scanpipe.tests.test_sca_integrations
58+
./manage.py test scanpipe.tests.test_integrations_sca
5959
6060
5. Commit both the SBOM file and dictionary entry.
6161
@@ -76,7 +76,7 @@
7676
# - ``packages_vulnerable``: Vulnerable DiscoveredPackages
7777
# - ``dependencies``: DiscoveredDependencies
7878
# - ``purls``: The list of PURLs present in the SBOM
79-
SCA_INTEGRATIONS_TEST_DATA = {
79+
TEST_DATA = {
8080
### Anchore Grype
8181
# $ grype -v -o cyclonedx-json \
8282
# --file anchore-alpine-3.17-sbom.json alpine:3.17.0
@@ -349,27 +349,22 @@
349349
}
350350

351351

352-
class ScanPipeSCAIntegrationsTest(TestCase):
352+
class ScanPipeIntegrationsBaseTest(TestCase):
353353
"""
354354
Run consistency checks across all SBOM integration test files.
355355
356-
For each SBOM listed in ``SCA_INTEGRATIONS_TEST_DATA``, this test:
356+
For each SBOM listed in ``TEST_DATA``, this test:
357357
- Loads the SBOM into a temporary ScanCode.io project.
358358
- Executes the ``load_sbom`` pipeline.
359359
- Verifies that the number of resources, packages, vulnerable packages,
360360
and dependencies match the expected values.
361361
"""
362362

363-
data = Path(__file__).parent / "data"
364-
365-
def test_scanpipe_sca_integrations_tools(self):
366-
"""Loop through all SBOM files and run integration checks."""
367-
for sbom_filename, expected_results in SCA_INTEGRATIONS_TEST_DATA.items():
368-
self._test_scanpipe_sca_integrations_tool(sbom_filename, expected_results)
363+
data = None
369364

370365
def _test_scanpipe_sca_integrations_tool(self, sbom_filename, expected_results):
371366
"""Run a single SBOM integration test."""
372-
input_location = self.data / "sca-integrations" / sbom_filename
367+
input_location = self.data / sbom_filename
373368

374369
# Create a fresh project and load the SBOM into it
375370
project = make_project()
@@ -410,3 +405,12 @@ def _test_scanpipe_sca_integrations_tool(self, sbom_filename, expected_results):
410405
purls_diff = benchmark.compare_purls(project, expected_purls)
411406
formatted_diff = "\n".join(purls_diff)
412407
self.assertFalse(purls_diff, msg=f"\n{sbom_filename}\n{formatted_diff}")
408+
409+
410+
class ScanPipeIntegrationsSCAToolsTest(ScanPipeIntegrationsBaseTest):
411+
data = Path(__file__).parent / "data" / "integrations-sca"
412+
413+
def test_scanpipe_integrations_sca_tools(self):
414+
"""Loop through all SBOM files and run integration checks."""
415+
for sbom_filename, expected_results in TEST_DATA.items():
416+
self._test_scanpipe_sca_integrations_tool(sbom_filename, expected_results)

0 commit comments

Comments
 (0)