From 1ce070beac4f7f91ca6215e5aeae58fa63057fd4 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 29 Apr 2023 16:44:10 +0200 Subject: [PATCH] split tests --- src/test/python/domain/test_c4k.py | 99 +++++++++++++++++ .../domain/{test_domain.py => test_common.py} | 100 ------------------ 2 files changed, 99 insertions(+), 100 deletions(-) create mode 100644 src/test/python/domain/test_c4k.py rename src/test/python/domain/{test_domain.py => test_common.py} (55%) diff --git a/src/test/python/domain/test_c4k.py b/src/test/python/domain/test_c4k.py new file mode 100644 index 0000000..175980e --- /dev/null +++ b/src/test/python/domain/test_c4k.py @@ -0,0 +1,99 @@ +import pytest +from pathlib import Path +from src.main.python.ddadevops.domain.common import ( + DnsRecord, + BuildType, +) +from src.main.python.ddadevops.domain.c4k import C4k +from .test_helper import build_devops + + +def test_creation(): + sut = build_devops({}) + assert BuildType.C4K in sut.specialized_builds + + +def test_c4k_should_calculate_config(): + sut = build_devops({}) + with pytest.raises(Exception): + sut.specialized_builds[BuildType.C4K].config() + + sut = build_devops({}) + c4k = sut.specialized_builds[BuildType.C4K] + c4k.update_runtime_config(DnsRecord("fqdn")) + assert { + "fqdn": "fqdn", + "mon-cfg": { + "cluster-name": "module", + "cluster-stage": "test", + "grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push", + }, + } == c4k.config() + + sut = build_devops( + { + "c4k_config": {"test": "test"}, + } + ) + c4k = sut.specialized_builds[BuildType.C4K] + c4k.update_runtime_config(DnsRecord("fqdn")) + assert { + "test": "test", + "fqdn": "fqdn", + "mon-cfg": { + "cluster-name": "module", + "cluster-stage": "test", + "grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push", + }, + } == c4k.config() + + +def test_c4k_should_calculate_auth(): + sut = build_devops({}) + c4k = sut.specialized_builds[BuildType.C4K] + assert { + "mon-auth": {"grafana-cloud-password": "password", "grafana-cloud-user": "user"} + } == c4k.auth() + + sut = build_devops( + { + "c4k_auth": {"test": "test"}, + } + ) + c4k = sut.specialized_builds[BuildType.C4K] + assert { + "test": "test", + "mon-auth": { + "grafana-cloud-password": "password", + "grafana-cloud-user": "user", + }, + } == c4k.auth() + + +def test_c4k_build_should_calculate_command(): + sut = build_devops( + { + "project_root_path": ".", + } + ) + assert ( + "c4k-module-standalone.jar " + + "./target/name/module/out_c4k_config.yaml " + + "./target/name/module/out_c4k_auth.yaml > " + + "./target/name/module/out_module.yaml" + == sut.specialized_builds[BuildType.C4K].command(sut) + ) + + sut = build_devops( + { + "project_root_path": ".", + "c4k_executabel_name": "executabel_name", + } + ) + assert ( + "c4k-executabel_name-standalone.jar " + + "./target/name/module/out_c4k_config.yaml " + + "./target/name/module/out_c4k_auth.yaml > " + + "./target/name/module/out_module.yaml" + == sut.specialized_builds[BuildType.C4K].command(sut) + ) diff --git a/src/test/python/domain/test_domain.py b/src/test/python/domain/test_common.py similarity index 55% rename from src/test/python/domain/test_domain.py rename to src/test/python/domain/test_common.py index 00ed640..5c2bd6d 100644 --- a/src/test/python/domain/test_domain.py +++ b/src/test/python/domain/test_common.py @@ -13,8 +13,6 @@ from src.main.python.ddadevops.domain import ( ReleaseContext, ) from src.main.python.ddadevops.domain.image import Image -from src.main.python.ddadevops.domain.c4k import C4k -from src.main.python.ddadevops.c4k_build import add_c4k_mixin_config from .test_helper import build_devops @@ -69,104 +67,6 @@ def test_should_validate_DnsRecord(): sut = DnsRecord("name", ipv6="1::") assert sut.is_valid() - -def test_c4k_build_should_update_fqdn(): - project_config = { - "stage": "test", - "name": "name", - "project_root_path": "mypath", - "module": "module", - "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, - config, - auth, - grafana_cloud_user="user", - grafana_cloud_password="password", - ) - - sut = C4k(project_config) - sut.update_runtime_config(DnsRecord("test.de", ipv6="1::")) - - assert { - "issuer": "staging", - "fqdn": "test.de", - "mon-cfg": { - "cluster-name": "module", - "cluster-stage": "test", - "grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push", - }, - } == sut.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 - - -def test_c4k_build_should_calculate_command(): - devops = build_devops( - {"project_root_path": ".", "module": "module", "name": "name"} - ) - project_config = { - "stage": "test", - "name": "name", - "project_root_path": "", - "module": "module", - "build_dir_name": "target", - } - add_c4k_mixin_config( - project_config, - {}, - {}, - grafana_cloud_user="user", - grafana_cloud_password="password", - ) - sut = C4k(project_config) - assert ( - "c4k-module-standalone.jar " - + "./target/name/module/out_c4k_config.yaml " - + "./target/name/module/out_c4k_auth.yaml > " - + "./target/name/module/out_module.yaml" - == sut.command(devops) - ) - - project_config = { - "stage": "test", - "name": "name", - "project_root_path": "", - "module": "module", - "build_dir_name": "target", - } - add_c4k_mixin_config( - project_config, - {}, - {}, - executabel_name="executabel_name", - grafana_cloud_user="user", - grafana_cloud_password="password", - ) - sut = C4k(project_config) - assert ( - "c4k-executabel_name-standalone.jar " - + "./target/name/module/out_c4k_config.yaml " - + "./target/name/module/out_c4k_auth.yaml > " - + "./target/name/module/out_module.yaml" - == sut.command(devops) - ) - - def test_version(tmp_path: Path): version = Version(tmp_path, [1, 2, 3]) version.increment(ReleaseType.SNAPSHOT)