Skip to content

Commit

Permalink
test: purl in productinfo (#4476)
Browse files Browse the repository at this point in the history
fixes #4186

Adds unit tests for the ProductInfo class and functions.

Signed-off-by: Aryan Bakliwal <[email protected]>
  • Loading branch information
AryanBakliwal authored Oct 1, 2024
1 parent 66bf164 commit 1eaa910
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,88 @@ def test_cve_scanner(self):
assert (
instance_attrs["all_cve_data"] == DefaultDict[ProductInfo, CVEData]
), "Type of all_cve_data has been changed. Make sure it isn't breaking OutputEngine!"


class TestProductInfo:
"""Tests the ProductInfo class and functions"""

def test_product_info_with_purl(self):
vendor = "vendor_name"
product = "product_name"
version = "1.0.0"
location = "location/to/product"
purl = "pkg:type/namespace/product@version"

product_info = ProductInfo(
vendor=vendor,
product=product,
version=version,
location=location,
purl=purl,
)

assert product_info.vendor == vendor
assert product_info.product == product
assert product_info.version == version
assert product_info.location == location
assert product_info.purl == purl

def test_product_info_without_purl(self):
vendor = "vendor_name"
product = "product_name"
version = "1.0.0"
location = "location/to/product"

product_info = ProductInfo(
vendor=vendor, product=product, version=version, location=location
)

assert product_info.vendor == vendor
assert product_info.product == product
assert product_info.version == version
assert product_info.location == location
assert product_info.purl is None

def test_product_info_equality(self):
vendor = "vendor_name"
product = "product_name"
version = "1.0.0"
location_1 = "location/to/product"
location_2 = "different/location/to/product"
purl = "pkg:type/namespace/product@version"

product_info_1 = ProductInfo(
vendor=vendor,
product=product,
version=version,
location=location_1,
purl=purl,
)
product_info_2 = ProductInfo(
vendor=vendor, product=product, version=version, location=location_2
)

assert (
product_info_1 == product_info_2
) # Should be equal based on vendor, product, version

def test_product_info_hashing(self):
vendor = "vendor_name"
product = "product_name"
version = "1.0.0"
location_1 = "location/to/product"
location_2 = "different/location/to/product"
purl = "pkg:type/namespace/product@version"

product_info_1 = ProductInfo(
vendor=vendor,
product=product,
version=version,
location=location_1,
purl=purl,
)
product_info_2 = ProductInfo(
vendor=vendor, product=product, version=version, location=location_2
)

assert hash(product_info_1) == hash(product_info_2) # Hashes should be the same

0 comments on commit 1eaa910

Please sign in to comment.