mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-07-23 16:51:09 +02:00
Made canonical domains obligatorix
This commit is contained in:
parent
ff18c7cd73
commit
d94254effb
36
tests/integration/test_domains_canonical.py
Normal file
36
tests/integration/test_domains_canonical.py
Normal file
@ -0,0 +1,36 @@
|
||||
import unittest
|
||||
import yaml
|
||||
import glob
|
||||
import os
|
||||
|
||||
class TestWebRolesDomains(unittest.TestCase):
|
||||
def test_canonical_domains_present_and_not_empty(self):
|
||||
"""
|
||||
Check all roles/web-*/config/main.yml files:
|
||||
- must have domains.canonical defined
|
||||
- domains.canonical must not be empty dict, empty list, or empty string
|
||||
"""
|
||||
role_config_paths = glob.glob("roles/web-*/config/main.yml")
|
||||
self.assertTrue(role_config_paths, "No roles/web-*/config/main.yml files found.")
|
||||
|
||||
for path in role_config_paths:
|
||||
with self.subTest(role_config=path):
|
||||
with open(path, "r") as f:
|
||||
data = yaml.safe_load(f)
|
||||
|
||||
self.assertIsInstance(data, dict, f"YAML root is not a dict in {path}")
|
||||
|
||||
domains = data.get("domains")
|
||||
self.assertIsNotNone(domains, f"'domains' section missing in {path}")
|
||||
self.assertIsInstance(domains, dict, f"'domains' must be a dict in {path}")
|
||||
|
||||
canonical = domains.get("canonical")
|
||||
self.assertIsNotNone(canonical, f"'domains.canonical' missing in {path}")
|
||||
|
||||
# Check for emptiness
|
||||
empty_values = [{}, [], ""]
|
||||
self.assertNotIn(canonical, empty_values,
|
||||
f"'domains.canonical' in {path} must not be empty dict, list, or empty string")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user