Add another check to CiConfig.validate, and test for it

This commit is contained in:
Mikhail f. Shiryaev 2023-11-10 14:29:24 +01:00
parent db8a548718
commit 38b251946e
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 27 additions and 6 deletions

View File

@ -50,21 +50,27 @@ class CiConfig:
def validate(self) -> None:
errors = []
# All build configs must belong to build_report_config
for build_name in self.build_config.keys():
for name, build_config in self.build_config.items():
build_in_reports = False
for report_config in self.builds_report_config.values():
if build_name in report_config:
if name in report_config:
build_in_reports = True
break
# All build configs must belong to build_report_config
if not build_in_reports:
logging.error("Build name %s does not belong to build reports", name)
errors.append(f"Build name {name} does not belong to build reports")
# The name should be the same as build_config.name
if not build_config.name == name:
logging.error(
"Build name %s does not belong to build reports", build_name
"Build name '%s' does not match the config 'name' value '%s'",
name,
build_config.name,
)
errors.append(
f"Build name {build_name} does not belong to build reports"
f"Build name {name} does not match 'name' value '{build_config.name}'"
)
# And otherwise
# All build_report_config values should be in build_config.keys()
for build_report_name, build_names in self.builds_report_config.items():
missed_names = [
name for name in build_names if name not in self.build_config.keys()

View File

@ -0,0 +1,15 @@
#!/usr/bin/env python3
import unittest
class TestCiConfig(unittest.TestCase):
def test_no_errors_in_ci_config(self):
raised = None
try:
from ci_config import ( # pylint: disable=import-outside-toplevel
CI_CONFIG as _,
)
except Exception as exc:
raised = exc
self.assertIsNone(raised, f"CI_CONFIG import raised error {raised}")