mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Reorgenized test structure and added validation of inventory before deployment
This commit is contained in:
0
tests/unit/module_utils/__init__.py
Normal file
0
tests/unit/module_utils/__init__.py
Normal file
53
tests/unit/module_utils/test_cert_utils.py
Normal file
53
tests/unit/module_utils/test_cert_utils.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
# Add the project root/module_utils to the import path
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
PROJECT_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, "../../.."))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
from module_utils.cert_utils import CertUtils
|
||||
|
||||
|
||||
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),
|
||||
("api.example.com", "api.example.com", True),
|
||||
|
||||
# Wildcard matches
|
||||
("sub.example.com", "*.example.com", True),
|
||||
("www.example.com", "*.example.com", True),
|
||||
|
||||
# Wildcard non-matches
|
||||
("example.com", "*.example.com", False), # base domain is not covered
|
||||
("deep.sub.example.com", "*.example.com", False), # too deep
|
||||
("sub.deep.example.com", "*.deep.example.com", True), # correct: one level below
|
||||
|
||||
# Special cases
|
||||
("deep.api.example.com", "*.api.example.com", True),
|
||||
("api.example.com", "*.api.example.com", False), # base not covered by wildcard
|
||||
|
||||
# Completely different domains
|
||||
("test.other.com", "*.example.com", False),
|
||||
]
|
||||
|
||||
def test_matches(self):
|
||||
for domain, san, expected in self.tests:
|
||||
with self.subTest(domain=domain, san=san):
|
||||
result = CertUtils.matches(domain, san)
|
||||
self.assertEqual(
|
||||
result,
|
||||
expected,
|
||||
msg=f"CertUtils.matches({domain!r}, {san!r}) returned {result}, expected {expected}",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user