From 68ffbf23e20a7ec20448e4ac450fbb1a54251f02 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sun, 5 Mar 2023 13:01:17 +0100 Subject: [PATCH] last wip comment :-) --- src/test/python/test_domain.py | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/python/test_domain.py diff --git a/src/test/python/test_domain.py b/src/test/python/test_domain.py new file mode 100644 index 0000000..762e249 --- /dev/null +++ b/src/test/python/test_domain.py @@ -0,0 +1,83 @@ +from pybuilder.core import Project +from src.main.python.ddadevops.domain import Validateable, C4kBuild +from src.main.python.ddadevops.c4k_mixin import add_c4k_mixin_config + + +class TestValidateable(Validateable): + def __init__(self, value): + self.field = value + + def validate(self): + return self.__validate_is_not_empty__("field") + + +def test_should_validate_non_empty_strings(): + sut = TestValidateable("content") + assert sut.is_valid() + + sut = TestValidateable(None) + assert not sut.is_valid() + + sut = TestValidateable("") + assert not sut.is_valid() + + +def test_should_validate_non_empty_others(): + sut = TestValidateable(1) + assert sut.is_valid() + + sut = TestValidateable(1.0) + assert sut.is_valid() + + sut = TestValidateable(True) + assert sut.is_valid() + + sut = TestValidateable(None) + assert not sut.is_valid() + + +def test_validate_with_reason(): + sut = TestValidateable(None) + assert sut.validate()[0] == "Field 'field' may not be empty." + + +def test_c4k_build_should_update_fqdn(tmp_path): + name = "should_update_fqdn" + project = Project(str(tmp_path), name=name) + project_config = { + "stage": "test", + "project_root_path": str(tmp_path), + "module": name, + "build_dir_name": "target", + } + config = {"issuer": "staging"} + auth = { + "jvb-auth-password": "pw1", + "jicofo-auth-password": "pw2", + "jicofo-component-secret": "pw3", + } + add_c4k_mixin_config( + project_config, + name, + config, + auth, + grafana_cloud_user="user", + grafana_cloud_password="password", + ) + sut = C4kBuild(project, project_config) + + assert { + "issuer": "staging", + "mon-cfg": { + "cluster-name": "should_update_fqdn", + "cluster-stage": "test", + "grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push", + }, + } == sut.c4k_mixin_config + assert {'jicofo-auth-password': 'pw2', + 'jicofo-component-secret': 'pw3', + 'jvb-auth-password': 'pw1', + 'mon-auth': {'grafana-cloud-password': 'password', + 'grafana-cloud-user': 'user'}} == sut.c4k_mixin_auth + + sut.update_runtime_config