Skip to content

Commit 1eaa910

Browse files
test: purl in productinfo (#4476)
fixes #4186 Adds unit tests for the ProductInfo class and functions. Signed-off-by: Aryan Bakliwal <[email protected]>
1 parent 66bf164 commit 1eaa910

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

test/test_util.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,88 @@ def test_cve_scanner(self):
7777
assert (
7878
instance_attrs["all_cve_data"] == DefaultDict[ProductInfo, CVEData]
7979
), "Type of all_cve_data has been changed. Make sure it isn't breaking OutputEngine!"
80+
81+
82+
class TestProductInfo:
83+
"""Tests the ProductInfo class and functions"""
84+
85+
def test_product_info_with_purl(self):
86+
vendor = "vendor_name"
87+
product = "product_name"
88+
version = "1.0.0"
89+
location = "location/to/product"
90+
purl = "pkg:type/namespace/product@version"
91+
92+
product_info = ProductInfo(
93+
vendor=vendor,
94+
product=product,
95+
version=version,
96+
location=location,
97+
purl=purl,
98+
)
99+
100+
assert product_info.vendor == vendor
101+
assert product_info.product == product
102+
assert product_info.version == version
103+
assert product_info.location == location
104+
assert product_info.purl == purl
105+
106+
def test_product_info_without_purl(self):
107+
vendor = "vendor_name"
108+
product = "product_name"
109+
version = "1.0.0"
110+
location = "location/to/product"
111+
112+
product_info = ProductInfo(
113+
vendor=vendor, product=product, version=version, location=location
114+
)
115+
116+
assert product_info.vendor == vendor
117+
assert product_info.product == product
118+
assert product_info.version == version
119+
assert product_info.location == location
120+
assert product_info.purl is None
121+
122+
def test_product_info_equality(self):
123+
vendor = "vendor_name"
124+
product = "product_name"
125+
version = "1.0.0"
126+
location_1 = "location/to/product"
127+
location_2 = "different/location/to/product"
128+
purl = "pkg:type/namespace/product@version"
129+
130+
product_info_1 = ProductInfo(
131+
vendor=vendor,
132+
product=product,
133+
version=version,
134+
location=location_1,
135+
purl=purl,
136+
)
137+
product_info_2 = ProductInfo(
138+
vendor=vendor, product=product, version=version, location=location_2
139+
)
140+
141+
assert (
142+
product_info_1 == product_info_2
143+
) # Should be equal based on vendor, product, version
144+
145+
def test_product_info_hashing(self):
146+
vendor = "vendor_name"
147+
product = "product_name"
148+
version = "1.0.0"
149+
location_1 = "location/to/product"
150+
location_2 = "different/location/to/product"
151+
purl = "pkg:type/namespace/product@version"
152+
153+
product_info_1 = ProductInfo(
154+
vendor=vendor,
155+
product=product,
156+
version=version,
157+
location=location_1,
158+
purl=purl,
159+
)
160+
product_info_2 = ProductInfo(
161+
vendor=vendor, product=product, version=version, location=location_2
162+
)
163+
164+
assert hash(product_info_1) == hash(product_info_2) # Hashes should be the same

0 commit comments

Comments
 (0)