Rewrote to unittest

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-02 16:01:04 +02:00
parent ef663a1356
commit e807a3e956
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E

View File

@ -2,14 +2,27 @@
import os import os
import sys import sys
import unittest
# Add module_utils/ to the import path # Add module_utils/ to the import path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..", "module_utils"))) sys.path.insert(
0,
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"../../..",
"module_utils",
)
),
)
from module_utils.cert_utils import CertUtils from module_utils.cert_utils import CertUtils
def test_matches():
tests = [ class TestCertUtilsMatches(unittest.TestCase):
def setUp(self):
# prepare your test cases
self.tests = [
# Exact matches # Exact matches
("example.com", "example.com", True), ("example.com", "example.com", True),
("www.example.com", "www.example.com", True), ("www.example.com", "www.example.com", True),
@ -32,19 +45,16 @@ def test_matches():
("test.other.com", "*.example.com", False), ("test.other.com", "*.example.com", False),
] ]
passed = 0 def test_matches(self):
failed = 0 for domain, san, expected in self.tests:
with self.subTest(domain=domain, san=san):
for domain, san, expected in tests:
result = CertUtils.matches(domain, san) result = CertUtils.matches(domain, san)
if result == expected: self.assertEqual(
print(f"✅ PASS: {domain} vs {san} -> {result}") result,
passed += 1 expected,
else: msg=f"CertUtils.matches({domain!r}, {san!r}) returned {result}, expected {expected}",
print(f"❌ FAIL: {domain} vs {san} -> {result} (expected {expected})") )
failed += 1
print(f"\nSummary: {passed} passed, {failed} failed")
if __name__ == "__main__": if __name__ == "__main__":
test_matches() unittest.main()