Skip to content

Commit 826757d

Browse files
committed
Add test for get_advisory_url function
- Test string inputs (the bug fix scenario) - Test Path object inputs (original working case) - Test mixed Path/string inputs Addresses reviewer feedback Signed-off-by: Mrityunjay Raj <mr.raj.earth@gmail.com>
1 parent 1608222 commit 826757d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

vulnerabilities/tests/test_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,29 @@ def test_resolve_version_range_without_ignorable_versions():
151151
def test_get_severity_range():
152152
assert get_severity_range({""}) is None
153153
assert get_severity_range({}) is None
154+
155+
156+
def test_get_advisory_url():
157+
from pathlib import Path
158+
159+
from vulnerabilities.utils import get_advisory_url
160+
161+
# Test case 1: Both parameters as strings (the bug fix scenario)
162+
file_str = "/tmp/advisories/istio/ISTIO-2021-001.yaml"
163+
base_str = "/tmp/advisories"
164+
url = "https://github.com/istio/istio.io/tree/master/advisories/"
165+
166+
result = get_advisory_url(file_str, base_str, url)
167+
expected = "https://github.com/istio/istio.io/tree/master/advisories/istio/ISTIO-2021-001.yaml"
168+
assert result == expected
169+
170+
# Test case 2: Both parameters as Path objects
171+
file_path = Path("/tmp/advisories/istio/ISTIO-2021-001.yaml")
172+
base_path = Path("/tmp/advisories")
173+
174+
result = get_advisory_url(file_path, base_path, url)
175+
assert result == expected
176+
177+
# Test case 3: Mixed - file as Path, base_path as string
178+
result = get_advisory_url(file_path, base_str, url)
179+
assert result == expected

0 commit comments

Comments
 (0)