mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-07-03 23:52:04 +02:00
Rewrote to unittest
This commit is contained in:
parent
ef663a1356
commit
e807a3e956
@ -2,14 +2,27 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
# 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
|
||||
|
||||
def test_matches():
|
||||
tests = [
|
||||
|
||||
class TestCertUtilsMatches(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# prepare your test cases
|
||||
self.tests = [
|
||||
# Exact matches
|
||||
("example.com", "example.com", True),
|
||||
("www.example.com", "www.example.com", True),
|
||||
@ -32,19 +45,16 @@ def test_matches():
|
||||
("test.other.com", "*.example.com", False),
|
||||
]
|
||||
|
||||
passed = 0
|
||||
failed = 0
|
||||
|
||||
for domain, san, expected in tests:
|
||||
def test_matches(self):
|
||||
for domain, san, expected in self.tests:
|
||||
with self.subTest(domain=domain, san=san):
|
||||
result = CertUtils.matches(domain, san)
|
||||
if result == expected:
|
||||
print(f"✅ PASS: {domain} vs {san} -> {result}")
|
||||
passed += 1
|
||||
else:
|
||||
print(f"❌ FAIL: {domain} vs {san} -> {result} (expected {expected})")
|
||||
failed += 1
|
||||
self.assertEqual(
|
||||
result,
|
||||
expected,
|
||||
msg=f"CertUtils.matches({domain!r}, {san!r}) returned {result}, expected {expected}",
|
||||
)
|
||||
|
||||
print(f"\nSummary: {passed} passed, {failed} failed")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_matches()
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user