split tests

This commit is contained in:
Michael Jerger 2023-04-29 16:44:10 +02:00
parent 3495f69a6b
commit 1ce070beac
2 changed files with 99 additions and 100 deletions

View file

@ -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)
)

View file

@ -13,8 +13,6 @@ from src.main.python.ddadevops.domain import (
ReleaseContext, ReleaseContext,
) )
from src.main.python.ddadevops.domain.image import Image 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 from .test_helper import build_devops
@ -69,104 +67,6 @@ def test_should_validate_DnsRecord():
sut = DnsRecord("name", ipv6="1::") sut = DnsRecord("name", ipv6="1::")
assert sut.is_valid() 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): def test_version(tmp_path: Path):
version = Version(tmp_path, [1, 2, 3]) version = Version(tmp_path, [1, 2, 3])
version.increment(ReleaseType.SNAPSHOT) version.increment(ReleaseType.SNAPSHOT)